Skip to content

Instantly share code, notes, and snippets.

@rebx
Created October 10, 2011 22:52
Show Gist options
  • Save rebx/1276809 to your computer and use it in GitHub Desktop.
Save rebx/1276809 to your computer and use it in GitHub Desktop.
c has a size for void?
$ 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