c - 无符号转换 32 位

标签 c types casting integer

在 32 位系统上,简单的 unsigned 强制转换的行为是什么?

例如,假设我有一个 long var = 1,将 (unsigned)var 转换为 unsigned long无符号整型 ?

最佳答案

根据 C 标准(6.7.2 类型说明符,p.#2)

  1. ...Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
...
— unsigned, or unsigned int
...
— unsigned long, or unsigned long int

因此,转换表达式中的类型说明符 ( unsigned ) 表示类型 unsigned int

如果你想转换为 unsigned long 那么你应该写 ( unsigned long )( usigned long int )。正如引用中所写,您可以使用任何顺序的类型说明符,例如 ( int long unsigned )

关于c - 无符号转换 32 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56634366/

相关文章:

c++ - 转换为 bool 时没有得到 1

c - 使用 fscanf 在 c 中读取文件

c - 为什么我的 cd 命令不起作用?

python ctypes : get pointed type from a pointer variable

casting - 将字符数组转换为字符串

java - ClassCast 错误 : Java 7 vs Java 8

c - 从文件读取时忽略前两个单词

c - 映射库函数分配的间接指针 - C - OSX

scala - 左和右类型相同的任何一种的标准特化

types - 在 F# 中显式指定参数类型