Created
May 8, 2013 14:24
-
-
Save x2c3z4/5540792 to your computer and use it in GitHub Desktop.
print basic C type size
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
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//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