Skip to content

Instantly share code, notes, and snippets.

@kisel
Last active August 29, 2015 14:02
Show Gist options
  • Save kisel/b6f4f371a0125dc67d5a to your computer and use it in GitHub Desktop.
Save kisel/b6f4f371a0125dc67d5a to your computer and use it in GitHub Desktop.
/*
usage:
gcc -o show_c_sizeof show_c_sizeof.c && ./show_c_sizeof
*/
#include <stdio.h>
#define S(type) \
printf("sizeof(" #type ") = %d\n", (int)(sizeof(type)))
int main()
{
S(bool);
S(char);
S(short);
S(int);
S(long);
S(long long);
S(size_t);
return 0;
}
## 32bit system
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(long) = 4
sizeof(long long) = 8
sizeof(size_t) = 4
## 64 bit Linux
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(long) = 8
sizeof(long long) = 8
sizeof(size_t) = 8
## 64 bit Mac OS
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(long) = 8
sizeof(long long) = 8
sizeof(size_t) = 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment