ROBOTC.net forums
http://www.robotc.net/forums/

Problem with inline functions in 1.93
http://www.robotc.net/forums/viewtopic.php?f=52&t=1843
Page 1 of 1

Author:  johncdelacy [ Wed Sep 16, 2009 1:57 am ]
Post subject:  Problem with inline functions in 1.93

With 1.93 this compiles:

Code:
////////////////////////////////////////////////////////////////////////////////
//
// min
//
////////////////////////////////////////////////////////////////////////////////
int  min(int value1, int value2)
{
   return (value2 > value1 ? value1 : value2);
}


This doesn't:

Code:
////////////////////////////////////////////////////////////////////////////////
//
// min
//
////////////////////////////////////////////////////////////////////////////////
int inline min(int value1, int value2)
{
   return (value2 > value1 ? value1 : value2);
}


I get this error:

**Error**:Empty 'non-void' function not allowed. 'return' statement is required

with a red X on the close brace.

John DeLacy
Benson Robotics Club

Author:  l0jec [ Wed Sep 16, 2009 7:58 am ]
Post subject:  Re: Problem with inline functions in 1.93

Yes, I posted the same bug in 1.91 here: http://www.robotc.net/forums/viewtopic.php?f=33&t=1838.

Depending on what your inline function is doing, you may be able to write an extra copy of it with another name for each task you are calling it from. This is a poor approach in my mind, but it may hold us over until the inline function is properly fixed?

Author:  Ford Prefect [ Wed Sep 16, 2009 8:19 am ]
Post subject:  Re: Problem with inline functions in 1.93

well,
this indeed is a VERY POOR approach :(

inline worked well with all my code from 1.10 up to 1.45, see this:

Code:
///////////////////////////////////////////////////////////////////////
// math.h                                                            //
// mathematische Konstanten und Funktionen                           //
// Version 0.1.1                                                     //
///////////////////////////////////////////////////////////////////////

#define _MATH_H

//===================================================================
// mathematische Konstanten und Funktionen
//===================================================================

// Eulersche Zahl E:
const float E=2.718281828450945235360287471352662497757247093699959574966967627724076630353547594571;

//********************************************

inline int  min(int a, int b)
{
  return(a<b ? a:b);
}


inline float min(float a, float b)
{
   return (a<b ? a:b);
}

//********************************************

inline int  max(int a, int b)
{
   return (a>b ? a:b);
}


inline float max(float a, float b)
{
  return (a>b ? a : b);
}

//********************************************

inline int round(float f)
{
  if (f>=0) {return (int)(f + 0.5);}
  else
  {return (int)(f - 0.5);}
}

//********************************************


// ArcusTangens mit Sonderfaellen; Angabe in radians!
// x=Ankathete y=Gegenkathete Tangens=y/x

inline float atan2(float x, float y)
{
  float phi;   //phi=Bogenmass;

   if (x>0) {phi=atan(y/x);}
   else
   if ((x<0)&&(y>=0))  {phi=PI+atan(y/x);}
   else
   if ((x<0)&&(y<0))   {phi=-PI+atan(y/x);}
   else
   if ((x==0)&&(y>0))  {phi=PI/2;}
   else
   if ((x==0)&&(y<0))  {phi=-PI/2;}
   else
   if ((x==0)&&(y==0)) {phi=0;}

   return phi;
}

// ArcusTangens; dto., aber mit Angabe in Grad!

inline float atan2Degrees(float x, float y)
{
  return(radiansToDegrees(atan2(x,y)));
}


//********************************************

// Tangens Hyperbolicus

inline float tanh(float x)
{
   float e2x;
   e2x=exp(2*x);
   return((e2x-1)/(e2x+1));
}


//********************************************


// for  int values
inline bool IsInRange(int Wert, int Basis, int Toleranz)
{
   return((Wert>=Basis-Toleranz) && (Wert<=Basis+Toleranz));
}

// for float values
inline bool IsInRange(float Wert, float Basis, float Toleranz)
{
   return((Wert>=Basis-Toleranz) && (Wert<=Basis+Toleranz));
}



//===================================================================
//===================================================================


That it currently doesn't compile correctly must be a new issue.

And you can't expect programmers to write a copy for all functions for all tasks, do you?? :poke:

Author:  mightor [ Wed Sep 16, 2009 8:26 am ]
Post subject:  Re: Problem with inline functions in 1.93

The bug is on the issue list and has been assigned to be fixed.

Author:  kareka [ Sun Jul 18, 2010 2:29 pm ]
Post subject:  Re: Problem with inline functions in 1.93

Here we are at 2.02 and the same problem still remains !!!

Author:  mightor [ Sun Jul 18, 2010 2:50 pm ]
Post subject:  Re: Problem with inline functions in 1.93

What problem are you seeing?

- Xander

Author:  Gary Samad [ Sun Jul 18, 2010 5:10 pm ]
Post subject:  Re: Problem with inline functions in 1.93

I'm not sure if this is the problem, but this is not exactly the correct syntax in C:

int inline min(int value1, int value2)

The correct syntax is:

inline int min(int value1, int value2)

Does this fix it?

cu,
Gary

Author:  mightor [ Sun Jul 18, 2010 5:18 pm ]
Post subject:  Re: Problem with inline functions in 1.93

As of 2.16.1, inline functions are turned into normal functions. inline functions are no longer supported.

- Xander

Author:  kareka [ Sun Jul 18, 2010 5:56 pm ]
Post subject:  Re: Problem with inline functions in 1.93

What I'm saying is that this still doesn't work:

-------------------------------------------
inline int GetDistance()
{
return(5);
}

task main()
{
int Distance;

Distance = GetDistance();
}
--------------------------------------------

Author:  kareka [ Sun Jul 18, 2010 5:59 pm ]
Post subject:  Re: Problem with inline functions in 1.93

mightor what is the workaround for not having inline functions ?

Author:  Gary Samad [ Sun Jul 18, 2010 6:28 pm ]
Post subject:  Re: Problem with inline functions in 1.93

kareka wrote:
mightor what is the workaround for not having inline functions ?

What about just removing the "inline" keyword? There's normally no need for an inline function in C, it's just an optimization suggestion, but I did notice that RobotC required the use of inline functions if the same function was called from two different tasks - I'm not sure why. Sounds like Xander is saying inline functions are no longer needed or supported, so maybe try just removing the "inline" keyword?

cu,
Gary

Author:  kareka [ Sun Jul 18, 2010 7:30 pm ]
Post subject:  Re: Problem with inline functions in 1.93

Gary Samad I'm using the "inline" statement because I found I need it.

For example I have a fuction that handles a Mindsensors "DIST-Nx-Long-v2" sensor reading the distance.
That function is called from more that one task. I'm using the same sensor for different things.

Pure C programming is one thing. But when we start controling hardware things complicate.

Author:  Aswin [ Wed Oct 13, 2010 8:11 am ]
Post subject:  Re: Problem with inline functions in 1.93

kareka wrote:
Gary Samad I'm using the "inline" statement because I found I need it.

For example I have a fuction that handles a Mindsensors "DIST-Nx-Long-v2" sensor reading the distance.
That function is called from more that one task. I'm using the same sensor for different things.

Pure C programming is one thing. But when we start controling hardware things complicate.


You can start a seperate task to address the sensor and store its results in a global variable.

btw. Inline might no longer be supported, it is still suggested by the compiler!

Author:  MHTS [ Thu Nov 11, 2010 3:32 pm ]
Post subject:  Re: Problem with inline functions in 1.93

If you are compelled to use inline functions, you can always do this:
Code:
#define min(x, y)  (((x) > (y))? (y): (x))

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/