Created
September 15, 2011 07:11
-
-
Save kosh04/1218712 to your computer and use it in GitHub Desktop.
sizeof演算子で変数の大きさを調べる
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> | |
#include <stddef.h> | |
#include <sys/types.h> | |
#include <wchar.h> | |
#include <time.h> | |
// XXX: "%zd" format cannot work in VC, MinGW | |
#define prints(type) printf(#type "\t\t" "%lu\n", (unsigned long)sizeof(type)) | |
int main(void) | |
{ | |
printf("Type" "\t\t" "Byte\n"); | |
printf("----\n"); | |
prints(char); | |
prints(char *); | |
prints(short); | |
prints(int); | |
prints(long); | |
prints(long long); | |
prints(float); | |
prints(double); | |
prints(long double); | |
prints(void); | |
prints(void *); | |
prints(size_t); | |
prints(ssize_t); | |
prints(time_t); | |
prints(off_t); | |
prints(wchar_t); | |
prints(intptr_t); | |
prints(ptrdiff_t); | |
prints(_Bool); | |
return 0; | |
} |
// win32 LSI C-86 試食版
char 1
char * 2
short 2
int 2
long 4
long long undef
float 4
double 8
long double 10
void undef
void * 2
size_t 2
ssize_t undef
time_t 4
off_t 4
wchar_t undef
intptr_t undef
ptrdiff_t 2
_Bool undef
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// FreeBSD 8.2 amd64
char 1
char * 8
short 2
int 4
long 8
long long 8
float 4
double 8
long double 16
void 1
void * 8
size_t 8
ssize_t 8
time_t 8
off_t 8
wchar_t 4
intptr_t 8
ptrdiff_t 8
_Bool 1