It seems sizeof is not a real function?
for example, if you write like this:
int i=0;
printf("%d\n", sizeof(++i));
printf("%d\n", i);
You may get output like:
4
0
And when you dig into the assemble code, you'll find sth like this:
movl $4, %esi
leaq LC0(%rip), %rdi
xorl %eax, %eax
call _printf
So, the compiler put directly the constant "4" as parameters of printf add call it. Then what does sizeof do?
Best Answer
You know, there's a reason why there are standard documents (3.8MB PDF); C99, section 6.5.3.4, ยง2:
In response to ibread's comment, here's an example for the C99 variable length array case:
The size of
foo
is no longer known at compile-time and has to be determined at run-time. The generated assembly looks quite weird, so don't ask me about implementation details...