1.unsigned long 与 unsigned int 等同,可以缩写为unsigned 。
2.LLP64编译模型各类型的长度:
环境:win-64/vs 2013
代码:
1 std::cout <<"size of (int): "<< sizeof(int ) 2 << "Byte."<<std::endl; 3 std::cout << "size of (long): " << sizeof(long ) 4 << "Byte." << std::endl; 5 std::cout << "size of (long long): " << sizeof(long long ) 6 << "Byte." << std::endl; 7 std::cout << "size of (unsigned int):" <<sizeof(unsigned int ) 8 << "Byte." << std::endl; 9 std::cout << "size of (unsigned long): " << sizeof(unsigned long) 10 << "Byte." << std::endl; 11 std::cout << "size of (unsigned long long): " << sizeof(unsigned long long) 12 << "Byte." << std::endl;
结果:
4.选择类型经验:
a.明确知晓数值不可能是负时,选用unsigned类型;
b.实际应用int 与 long 是相同的大小;
c.char的类型的default可能是unsigned 或signed 类型的,具体取决于机器;因此应该明确指明是unsigned char 或者 unsigned char;
d.执行浮点数运算选用double。因为float通常精度不够而且双精度浮点数和单精度浮点数的计算代价相差无几;
e.long double 提供的精度在一般情况下是没有必要的,况且它带来的运算时耗也不容忽视;
时间: 2024-10-23 20:38:55