sizeof( function )

Segher Boessenkool segher@kernel.crashing.org
Tue Jun 12 16:56:00 GMT 2007


>> Not that is of great importance, but does anyone know why
>>
>> int main( void )
>> {
>>         return printf( "%d\n", ( int )sizeof( main ) );
>> }
>>
>> prints 1 ? :)

> It is invalid to use sizeof() with a function
> type expression (C99 §6.5.3.4 para. 1) and hence this code invokes
> undefined behavior.  gcc gives a warning if you compile with -pedantic,
> but otherwise it apparently just returns 1;

See the description of -Wpointer-arith in the Fine Manual.


Segher



More information about the Gcc-help mailing list