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 support@ccsinfo.com

Function pointer comparison. Bug in v4.071?

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



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Function pointer comparison. Bug in v4.071?
PostPosted: Fri Jun 27, 2008 12:01 am     Reply with quote

Colleagues,

It’s great that v4 supports function pointers. However, it doesn’t seem to support the function pointer comparison at the moment.

Code:

typedef int8 (*fp)(int8, int8); // typedef for our function pointer

int8 do_it(int8 ix, int8 iy)
{
   return (ix + iy);
}

// more functions that fit the fp typedef

void main()
{
// . . .
   fpFoo = &do_it;   // initialize the function pointer.
   // . . .
   if (fpFoo == &do_it)   // during compilation, this line generates ERROR 48: Expecting a (
   {
      // . . .
   }
// . . .
}



- Nick
_________________
Read the label, before opening a can of worms.


Last edited by kender on Fri Jun 27, 2008 12:06 pm; edited 1 time in total
Ttelmah
Guest







PostPosted: Fri Jun 27, 2008 2:05 am     Reply with quote

The function name itself, _is_ the function's address. You don't need the '&' when referring to it.
Use a cast for comparisons. Given that fpFoo, is the address of a function, it expects to receive two variables. So:
Code:

typedef int8 (*fp)(int8, int8); // typedef for our function pointer

int8 do_it(int8 ix, int8 iy)
{
   return (ix + iy);
}

// more functions that fit the fp typedef

void main()
{
// . . .
   fp fpFoo;
   fpFoo = do_it;   // initialize the function pointer.
   // . . .
   if ((int16)fpFoo == (int16)do_it)   
   {
      // . . .
   }
// . . .
}


Best Wishes
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