Created
October 10, 2011 22:52
-
-
Save rebx/1276809 to your computer and use it in GitHub Desktop.
c has a size for void?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat voidsize.c | |
#include <stdio.h> | |
int main(void) { | |
printf("void size: %d\n", sizeof(void)); | |
return 0; | |
} | |
$ make voidsize | |
cc voidsize.c -o voidsize | |
voidsize.c: In function ‘main’: | |
voidsize.c:4: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’ | |
[compiles] | |
-bash-3.2$ ./voidsize | |
void size: 1 | |
but... | |
$ env CC=g++ make voidsize | |
g++ voidsize.c -o voidsize | |
voidsize.c: In function ‘int main()’: | |
voidsize.c:4: error: invalid application of ‘sizeof’ to a void type | |
voidsize.c:4: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’ | |
make: *** [voidsize] Error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment