View unanswered posts | View active topics It is currently Tue Sep 23, 2014 12:54 pm






Reply to topic  [ 14 posts ] 
Problem with inline functions in 1.93 
Author Message
Rookie

Joined: Mon Dec 15, 2008 3:30 pm
Posts: 7
Post 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


Wed Sep 16, 2009 1:57 am
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post 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?


Wed Sep 16, 2009 7:58 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Sep 16, 2009 8:19 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Problem with inline functions in 1.93
The bug is on the issue list and has been assigned to be fixed.

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Sep 16, 2009 8:26 am
Profile WWW
Rookie

Joined: Sun Jul 18, 2010 2:14 pm
Posts: 4
Post Re: Problem with inline functions in 1.93
Here we are at 2.02 and the same problem still remains !!!


Sun Jul 18, 2010 2:29 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Problem with inline functions in 1.93
What problem are you seeing?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jul 18, 2010 2:50 pm
Profile WWW
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post 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


Sun Jul 18, 2010 5:10 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jul 18, 2010 5:18 pm
Profile WWW
Rookie

Joined: Sun Jul 18, 2010 2:14 pm
Posts: 4
Post 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();
}
--------------------------------------------


Sun Jul 18, 2010 5:56 pm
Profile
Rookie

Joined: Sun Jul 18, 2010 2:14 pm
Posts: 4
Post Re: Problem with inline functions in 1.93
mightor what is the workaround for not having inline functions ?


Sun Jul 18, 2010 5:59 pm
Profile
Expert

Joined: Mon Mar 15, 2010 4:24 pm
Posts: 124
Post 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


Sun Jul 18, 2010 6:28 pm
Profile
Rookie

Joined: Sun Jul 18, 2010 2:14 pm
Posts: 4
Post 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.


Sun Jul 18, 2010 7:30 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post 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!

_________________
My most recent blog: A grain of sugar


Wed Oct 13, 2010 8:11 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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))


Thu Nov 11, 2010 3:32 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.