位数比较
由于数据的长度和平台相关,所以基于 64 位系统比较。
Windows | Linux | |
---|---|---|
unsigned int | 32 bits/4294967295 | 32 bits |
unsigned long | 32 bits | 64 bits/18446744073709551615 |
unsigned long long | 64 bits | 64 bits |
size_t | 32 bits | 64 bits |
可以看到,size_t 和 unsigned long 比较同步。另外 ssize_t 和 size_t 的关系就像 int 和 unsigned int 的关系。(参考1,参考2)
格式控制(printf)
length | d i | u o x X | f F e E g G a A | c | s | p | n |
---|---|---|---|---|---|---|---|
(none) | int | unsigned int | double | int | char* | void* | int* |
hh | signed char | unsigned char | signed char* | ||||
h | short int | unsigned short int | short int* | ||||
l | long int | unsigned long int | wint_t | wchar_t* | long int* | ||
ll | long long int | unsigned long long int | long long int* | ||||
j | intmax_t | uintmax_t | intmax_t* | ||||
z | size_t | size_t | size_t* | ||||
t | ptrdiff_t | ptrdiff_t | ptrdiff_t* | ||||
L | long double |
(参考)
测试代码
#include <cstdio>
int main()
{
unsigned int ui = -1;
unsigned long ul = -1;
unsigned long long ull = -1;
size_t st = -1;
printf("ui=%u,ul=%lu,ull=%llu,st=%zu\n", ui, ul, ull, st);
return 0;
}
测试结果
- Windows
- Linux
原文地址:https://www.cnblogs.com/hereis00/p/9994312.html
时间: 2024-11-08 09:09:47