편집 : 어리석은 질문, 나는 형식 식별자를 간과했다.unsigned long long은 int (4 바이트) 범위로 고정되며, 그렇다면 왜 메모리에서 8 바이트입니까?
나는 부호없는 약간 유형의 크기 및 그들의 최대 가치를 프로그램이 움켜 잡도록했다. 이것은 나의주의에 변칙을 가져왔다. 심지어 unsigned long long
이 8 바이트라고 생각했다하더라도, 그 범위는 4 바이트 범위로 고정 된 것으로 보인다. 내가 unsigned long long
만 (전 이적 또는 오히려> = long int
> = int
)를 int
을 유지하기 위해 적어도 충분히 크게 표준에 의해 정의되는 것을 이해
질문 (문자는 보장 된 8 비트 바이트) . 그러나 4 바이트 범위로 제한되는 경우 int
과 같은 크기가 아닌 8 바이트의 메모리를 사용하는 이유는 무엇입니까? 여기
unsigned char: 255 1*sizeof(char) unsigned short: 65535 2*sizeof(char) unsigned short int: 65535 2*sizeof(char) unsigned int: 4294967295 4*sizeof(char) unsigned long int: 4294967295 4*sizeof(char) unsigned long long int: 4294967295 8*sizeof(char) //range[0..18446744073709551615] unsigned long: 4294967295 4*sizeof(char) unsigned long long: 4294967295 8*sizeof(char) //range[0..18446744073709551615]
내가 사용하는 소스입니다 : #include <iostream>
#include <cstdio>
int main(void){
std::cout << "Type sizes: (multiples of char)"<< std::endl << "char: " << sizeof(char) << std::endl <<\
"short: " << sizeof() << std::endl <<\
"short int: " << sizeof(short int) << std::endl << std::endl <<\
"int: " << sizeof(int) << std::endl <<\
"long int: " << sizeof(long int) << std::endl <<\
"long long int: " << sizeof(long long int) << std::endl << std::endl <<\
"long: " << sizeof(long) << std::endl <<\
"long long: " << sizeof(long long) << std::endl << std::endl <<\
"float: " << sizeof(float) << std::endl <<\
"double: " << sizeof(double) << std::endl;
unsigned char c = -1;
unsigned short s1 = -1;
unsigned short int s2 = -1;
unsigned int i = -1;
unsigned long int i1 = -1;
unsigned long long int i2 = -1;
unsigned long l = -1;
unsigned long long l1 = -1;
printf("\
\nUnsigned Max: \n\
\nchar: %u\
\nshort: %u\
\nshort int: %u\
\nint: %u\
\nlong int: %u\
\nlong long int: %u\
\nlong: %u\
\nlong long: %u\
", c, s1, s2, i, i1, i2, l, l1);
return 0;
}
나는 테스트가 깨진 것 같아요. "unsigned long long"은 최소한 2^64 - 1까지 올라갈 것을 보장합니다. – Kyurem
@Kyurem 나는 이것을 질문에 사용했던 코드를 편집했습니다. 문제가 실제로 ideone.com에서 테스트 한 것일 수 있습니다. 편집, 맞습니다. 잘못된 형식 토큰을 사용하고 있는데 확인하지 않았습니다. – GRAYgoose124
표준에서는 'long long int'가 64 비트 이상이어야합니다. (원칙적으로 바이트는 8 비트보다 더 넓을 수 있지만 [DSP] (http://en.wikipedia.org/wiki/Digital_signal_processor)에서만'CHAR_BIT> 8 '이 표시 될 가능성이 높습니다. –