반응형
iOS에서 Objective-C의 유형
iOS에서 Objective-C의 기본 데이터 유형에 대해 묻고 싶습니다.
변수가 표현되는 크기와 변수의 범위가 필요합니다.예를 들어 short int - 2 bytes - signed : - 32768 ~32767 및 unsigned : 0 ~65535 이것은 예에 불과합니다.
다음은 좋은 개요입니다.
http://reference.jumpingmonkey.org/programming_languages/objective-c/types.html
또는 다음 코드를 실행합니다.
32비트 프로세스:
NSLog(@"Primitive sizes:");
NSLog(@"The size of a char is: %d.", sizeof(char));
NSLog(@"The size of short is: %d.", sizeof(short));
NSLog(@"The size of int is: %d.", sizeof(int));
NSLog(@"The size of long is: %d.", sizeof(long));
NSLog(@"The size of long long is: %d.", sizeof(long long));
NSLog(@"The size of a unsigned char is: %d.", sizeof(unsigned char));
NSLog(@"The size of unsigned short is: %d.", sizeof(unsigned short));
NSLog(@"The size of unsigned int is: %d.", sizeof(unsigned int));
NSLog(@"The size of unsigned long is: %d.", sizeof(unsigned long));
NSLog(@"The size of unsigned long long is: %d.", sizeof(unsigned long long));
NSLog(@"The size of a float is: %d.", sizeof(float));
NSLog(@"The size of a double is %d.", sizeof(double));
NSLog(@"Ranges:");
NSLog(@"CHAR_MIN: %c", CHAR_MIN);
NSLog(@"CHAR_MAX: %c", CHAR_MAX);
NSLog(@"SHRT_MIN: %hi", SHRT_MIN); // signed short int
NSLog(@"SHRT_MAX: %hi", SHRT_MAX);
NSLog(@"INT_MIN: %i", INT_MIN);
NSLog(@"INT_MAX: %i", INT_MAX);
NSLog(@"LONG_MIN: %li", LONG_MIN); // signed long int
NSLog(@"LONG_MAX: %li", LONG_MAX);
NSLog(@"ULONG_MAX: %lu", ULONG_MAX); // unsigned long int
NSLog(@"LLONG_MIN: %lli", LLONG_MIN); // signed long long int
NSLog(@"LLONG_MAX: %lli", LLONG_MAX);
NSLog(@"ULLONG_MAX: %llu", ULLONG_MAX); // unsigned long long int
iPhone 3GS(iPod Touch 및 이전 iPhone에서도 동일한 결과를 얻을 수 있음)에서 다음과 같은 결과를 얻을 수 있습니다.
Primitive sizes:
The size of a char is: 1.
The size of short is: 2.
The size of int is: 4.
The size of long is: 4.
The size of long long is: 8.
The size of a unsigned char is: 1.
The size of unsigned short is: 2.
The size of unsigned int is: 4.
The size of unsigned long is: 4.
The size of unsigned long long is: 8.
The size of a float is: 4.
The size of a double is 8.
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -2147483648
LONG_MAX: 2147483647
ULONG_MAX: 4294967295
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
64비트 프로세스:
The size of a char is: 1.
The size of short is: 2.
The size of int is: 4.
The size of long is: 8.
The size of long long is: 8.
The size of a unsigned char is: 1.
The size of unsigned short is: 2.
The size of unsigned int is: 4.
The size of unsigned long is: 8.
The size of unsigned long long is: 8.
The size of a float is: 4.
The size of a double is 8.
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -9223372036854775808
LONG_MAX: 9223372036854775807
ULONG_MAX: 18446744073709551615
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
오브젝티브 C에서는 C99 고정폭 타입도 완벽하게 사용할 수 있습니다.
#import <stdint.h>
...
int32_t x; // guaranteed to be 32 bits on any platform
C 표준의 카피가 없는 경우는, 이 헤더에 무엇이 있는지를 Wikipedia 페이지에 적절히 기술하고 있습니다(단, Objective-C는 C의 작은 확장자이기 때문에, 이 헤더를 사용할 수 있습니다).헤더를 찾을 수도 있습니다.limits.h그리고.inttypes.h유용하게 쓰입니다.
새로운 64비트 아치 업데이트
Ranges:
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
INT_MIN: -2147483648
INT_MAX: 2147483647
LONG_MIN: -9223372036854775808
LONG_MAX: 9223372036854775807
ULONG_MAX: 18446744073709551615
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807
ULLONG_MAX: 18446744073709551615
언급URL : https://stackoverflow.com/questions/2107544/types-in-objective-c-on-ios
반응형
'code' 카테고리의 다른 글
| UIMage : 애스펙트 핏과 센터 표시 (0) | 2023.04.23 |
|---|---|
| 조건부 고유 제약 (0) | 2023.04.23 |
| iOS 7에서 내비게이션 바 색상을 변경하는 방법 (0) | 2023.04.23 |
| 텍스트 파일 끝에 출력을 추가하는 방법 (0) | 2023.04.23 |
| iPhone Core Data Unresolved 오류 저장 중 (0) | 2023.04.18 |