I
I
Igor2018-04-23 17:32:16
C++ / C#
Igor, 2018-04-23 17:32:16

Why is sizeof ( somefunc ) == 1?

Dear C Experts, attention to the question:
I always thought that I know C pretty well. But recently I came across this feature:

int main(){
    printf ( "%x %x\n" , sizeof ( &main ) , &main ) ;
    printf ( "%x %x\n" , sizeof ( main ) , main ) ;
    return 0 ;
}

and got the output:
8 87a05a0
1 87a05a0

The first line displays the expected values. In the second line, the value of main, as I expected, is the same as &main, but the fact that sizeof ( main ) is equal to 1 surprised me.
Can someone explain to me why this is so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-04-23
@assembled

https://msdn.microsoft.com/en-us/library/4s7x1k91.aspx

The sizeof operator never produces a result of 0, even for an empty class.
The sizeof operator cannot be used with the following operands:
Functions. (However, the sizeof operator can be applied to function pointers.)

G
GavriKos, 2018-04-23
@GavriKos

https://stackoverflow.com/questions/3838866/what-i...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question