C Integers 2018 8 1 1 GCC supports

  • Slides: 10
Download presentation
C Integers 袁建鹏 2018. 8. 1 1

C Integers 袁建鹏 2018. 8. 1 1

GCC supports only two’s complement integer types 0 0 1 0 x [1, 128]

GCC supports only two’s complement integer types 0 0 1 0 x [1, 128] ~ 1 1 0 1 255 -x + 1 1 1 0 255 -x+1 signed: -x unsigned: 256 -x 3

Integer Constants decimal-constant 123 Suffix Decimal Constant Octal or Hexadecimal Constant none int long

Integer Constants decimal-constant 123 Suffix Decimal Constant Octal or Hexadecimal Constant none int long int hexadecimal-constant 0 xffff int unsigned int long int unsigned long int U integer-suffix u U l L ll LL unsigned int unsigned long long int L long int long int unsigned long int UL unsinged long int unsigned long int LL long int unsigned long int ULL unsigned long int octal-constant 0644 A plus (+) or minus (-) symbol can precede an integer literal. The operator is treated as a unary operator rather than as part of the literal. 4

Convertions C 99:Conversion of an operand value to a compatible type causes no change

Convertions C 99:Conversion of an operand value to a compatible type causes no change to the value or the representation. Zero extentions 高位填充0 Signed extentions 高位填充符号位 从高精度到底精度整数转换:直接 截断取低部分!!! 当操作数为两种不同的类型时, 低rank类型的操作数被转换成高 类型的rank long double float unsigned long unsigned long unsigned int 5

Shift Logical Shift Left Logical Shift Right Arithmetic Shift Right 没有算术左移,why? 注意左边空出的所有位都填充符号位, 而不是只有最高位填充 6

Shift Logical Shift Left Logical Shift Right Arithmetic Shift Right 没有算术左移,why? 注意左边空出的所有位都填充符号位, 而不是只有最高位填充 6

Integer promotions C 99:If an int can represent all values of the original type,

Integer promotions C 99:If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. 48) All other types are unchanged by the integer promotions. 当char short出现在表达式中,不管有无符号,都被转换成int或者unsigned int Integer Overflow 溢出位被截断 7

思考1 memset(data, -1, len); 8

思考1 memset(data, -1, len); 8