Skip to content

Instantly share code, notes, and snippets.

@x2c3z4
Created May 8, 2013 14:24
Show Gist options
  • Save x2c3z4/5540792 to your computer and use it in GitHub Desktop.
Save x2c3z4/5540792 to your computer and use it in GitHub Desktop.
print basic C type size
#include <stdio.h>
#include <stdint.h> //for intptr_t ,added in C99
#define PRINT_SIZE(type) printf("sizeof(%s)=%d\n",#type,sizeof(type))
int main()
{
PRINT_SIZE(int);
PRINT_SIZE(long);
PRINT_SIZE(intptr_t);
PRINT_SIZE(void*);
PRINT_SIZE(long long);
PRINT_SIZE(size_t);
return 0;
}
//in my virtualbox there is a 32bit-ubuntu 12.04 ,but cpu is 64bit
//sizeof(int)=4
//sizeof(long)=4
//sizeof(intptr_t)=4
//sizeof(void*)=4
//sizeof(long long)=8
//sizeof(size_t)=4
@ustbgaofan
Copy link

//x86_64
sizeof(int)=4
sizeof(long)=8
sizeof(intptr_t)=8
sizeof(void*)=8
sizeof(long long)=8
sizeof(size_t)=8
sizeof(long unsigned int)=8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment