728x90

int가 사용 word size를 사용하기 때문에 32bit에서는 4byte, 64bit에서는 8byte를 사용한다.

이것은 상당히 유명한 내용이기 때문에 많이들 안다.

그런데 놓치기 쉬운 것은 long 이다.

linux에서 기본적으로 long이 unsigned int 로 되어 있기 때문에 마찬가지로 int와 동일한 크기를 가진다.


좀 더 깊이 들어가면 data model에 따라 조금씩 다르다고 하는데 자세히는 모르겠다


64-bit data models

Data model

short (integer)

int

long (integer)

long long

pointers/
size_t

Sample operating systems

LLP64/
IL32P64

16

32

32

64

64

Microsoft Windows(x86-64 and IA-64)

LP64/
I32LP64

16

32

64

64

64

Most Unixand Unix-likesystems, e.g. Solaris,LinuxBSD, and OS X;z/OS

ILP64

16

64

64

64

64

HAL Computer Systems port of Solaris toSPARC64

SILP64

64

64

64

64

64

"Classic"UNICOS[35](as opposed to UNICOS/mp, etc.)

 

<wikipedia : https://en.wikipedia.org/wiki/64-bit_computing>


간단한 test로 sizeof를 확인해봤다


printf("long: %d\n", sizeof(long));

printf("int : %d\n", sizeof(int));


32bit 
long: 4
int : 4

64bit

long: 8

int : 4


예상과 다르게 int가 4로 나왔다. 역시나 wiki는 똑똑한 사람들이 편집하는구나.

728x90

+ Recent posts