sh******@gmail.com writes:
[...]
/** fully compilable program */
#include <stdio.h>
void f(void ){
}
void (*g)(void);
int main(int argc, char *argv[]){
g = f;
printf("\n%u %u",sizeof f , sizeof g);
}
Eric Sosman already answered your question (this is a gcc-specific
extension), and you can get gcc to warn you about it with the proper
options). There are also two (unrelated) problems in your printf
call.
"%u" is the format for printing a value of type unsigned int; the
result of sizeof is of type size_t, which is an unsigned type that may
or may not be unsigned int. If, for example, unsigned int is 32 bits
and size_t is 64 bits, your program could misbehave.
You print the new-line character at the beginning of the line. You
should print it at the end. A new-line before the start of your
output is unnecessary. A missing new-line at the end of your output
can cause your program to misbehave, depending on the implementation.
A more portable version (without fixing the sizeof problem):
printf("%lu %lu\n",
(unsigned long)sizeof f,
(unsigned long)sizeof g);
C99 specifies "%zu" for printing a size_t value directly, but
unfortunately C99 support is not universal.
Finally, since main returns an int, you should return an int; add
"return 0;" before the closing "}". It's not required in C99, but in
my opinion it's good style.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"