CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Overloading function problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

Overloading function problem
PostPosted: Tue Nov 29, 2011 10:07 am     Reply with quote

I´m using function overloading.
One of them return an int value. Another function does not return(and does not give me errors)
Compiler CCS 4.124
PIC18F26J11

Code:
void RF24_comm(int comm) {
   delay_ms(1);
}
//
int RF24_comm(int comm) {
   int rv;                       
   delay_ms(1);
   return rv;                   
}
/************************************/
//Than I use the function overloaded
int RF24_TX_DATA() {    //blablabla
int data;
   //
   //   The line below is compiled without errors!
   RF24_comm(R_REGISTER|CONFIGURATION); //Read RF24 config register
   //
   //   The line below causes the error:
[b]   //   *** Error 51 "..." Line 262(43,44): A numeric expression must appear here
[/b]   //   1 Errors,  0 Warnings.
   data=RF24_comm(R_REGISTER|CONFIGURATION); //Read RF24 config register
   delay_ms(1);
}


Why this is happening?
I don´t know what to do.
It´s urgent. Thanks a lot!
_________________
Eduardo Guilherme Brandt
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Nov 29, 2011 10:31 am     Reply with quote

Oh dear Confused

Overloaded functions are not part of C, they are C++. CCS C supports some overloading however. As far as I can see its because CCS chose to implement part of its maths library in C rather than as intrinsic functions in the compiler. Because functions such as tan(), abs() and so on can take different types of arguments the compiler has to support overloading to get them to work. If you look in math.h you'll see all the overloads of the various maths functions. You can see exactly how they work too. Shocked HOWEVER overloading is something that CCS does primariliy for its own use, it is NOT in C.

Overloading stopped working in V4.125 and seems to be working in 4.127. Confused

In any case, overloading usually only works, in languages that support it, with different PARAMETERS in each overloaded case. C, and C++ and possibly C# don't really care about where any returned value goes. You can choose whether to use it or not, therefore the compiler cannot choose which overload to use based on returned result, only input parameters. Your overloads have the same parameters, therefore the compiler is going to get confused as to which it should be using.

The simple advice is do NOT use overloading. Keep right away from it. Its not C. Its not portable, and you may well see strange results when you use it. If you really do want to use it, then make sure your parameters are clearly different types (names are irrelevant).

Please write C, not try to write C++ and then wonder why it sort of, kind of breaks...ish.

RF Developer
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Tue Nov 29, 2011 10:50 am     Reply with quote

overloading functions seems so elegant! Crying or Very sad

Thanks again for advising me!
_________________
Eduardo Guilherme Brandt
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Tue Nov 29, 2011 10:58 am     Reply with quote

You´re right again: Compiler doesn´t care about returning parameter.
I killed the void input function and it compiled without errors, even using the function without getting values from it.

Thanks again
_________________
Eduardo Guilherme Brandt
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group