Vijay Kumar R Zanvar wrote:
> Hi,
>
>     Why the following program gives two different
> answers? -



>
> #include <stdio.h>
>
> int
> main ( void )
> {
>     printf ( "%u\n", sizeof ( main ) );


This is not really allowed. In ISO-C section 6.5.4.3 it is stated:
Constraints
1 The sizeof operator shall not be applied to an expression that has
function type or an incomplete type, to the parenthesized name of such a
type, or to an lvalue that designates a bit-field object.

If you turn on all options in gcc to obtain good warnings etc., you will
capture the error:

gcc -ansi -pedantic -Wall sizeof.c
sizeof.c: In function `main':
sizeof.c:6: warning: sizeof applied to a function type

The function main is of 'int (*f)(X)' type, where I am not entirely sure
how to specify X (variable argument list that does not follow ISO-C, may
be '...'). That is, main is of a function type.

I am uncertain that the return value of sizeof has an actual meaning in gcc.

>     printf ( "%u\n", sizeof ( main () ) );

This is the size of 'int' type.

>     return 0;
> }
>
> GCC 3.3.2 (Windows XP) gives the following o/p:
>
> 1
> 4
>
> Thanks.
>
> --
> Vijay Kumar R Zanvar
> My Home Page - http://www.oocities.org/vijoeyz/
>
>