Re: sizeof
Simon Marchi via Gdb <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2022-05-08 11:22, Russell Shaw wrote:
> When inspecting a C++ file, i get:
>
> (gdb) p sizeof(int())
> $82 = 1
>
> (gdb) p sizeof(int)
> $83 = 4
>
> Not right ?
>
> Package: gdb
> Version: 11.2-1
> on debian
The compiler seems to agree with GDB:
$ cat test.cpp
#include <stdio.h>
int main()
{
printf("%zu\n", sizeof(int));
printf("%zu\n", sizeof(int()));
}
$ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:6:19: warning: invalid application of ‘sizeof’ to a function type [-Wpointer-arith]
6 | printf("%zu\n", sizeof(int()));
| ^~~~~~~~~~~~~
$ ./a.out
4
1
I don't really know what sizeof(int()) means anyway. clang just rejects
it:
$ clang++ test.cpp
test.cpp:6:19: error: invalid application of 'sizeof' to a function type
printf("%zu\n", sizeof(int()));
^ ~~~~~~~
Simon