Having this simple code:
#include <stdio.h>
typedef struct
{
int a;
char c;
} foo;
void func(void *arg)
{
printf("sizeof arg: %ld\n", sizeof(*arg));
}
int main()
{
foo f = {6, 'c'};
func(&f);
printf("the real sizeof struct foo: %ld\n", sizeof(f));
}
output:
sizeof arg: 1
the real sizeof struct foo: 8
As you can see the function shows wrong result. If the reason is invalid application of ‘sizeof’ to incomplete type, then why does it shows sizeof arg: 1
? void
is not 1
bytes long, but incomplete type, so why is this result?