djgpp Integer made from pointer without a cast

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
OSNewbie

djgpp Integer made from pointer without a cast

Post by OSNewbie »

lets say i have a function putDec(int number) which prints the number in decimal. this works great. now i have a function enable_ints() or any function really, and i call putDec(enable_ints) because i want to know the address of the function. this compiles with a warning but appears to print the correct address.

the warning is what i am wondering about: it says (upon linking with LD): "Integer made from pointer without a cast" or something like that. is there another variable type besides int to use with pointers? i am new to C and djgpp and do not know all the variable types...

thanks

OSNewbie
Tim Robinson

RE:djgpp Integer made from pointer without a cast

Post by Tim Robinson »

Pointers are a separate type in C from integers. Pointers generally have a * in their name. For your putDec() function it's safe to type-cast the parameter (so you do putDec((int) enable_ints) ) but you should read up on pointers anyway, as they are vital.
phil

RE:djgpp Integer made from pointer without a cast

Post by phil »

a pointer to a function is what you use.  lets say the prototype for enable_ints() is:
void enable_ints(void);

then a pointer to that type of function (no parameters, no return) would be:
void (*pFunction)(void) = enable_ints;
Post Reply