在 32 位系统上,简单的 unsigned
强制转换的行为是什么?
例如,假设我有一个 long var = 1
,将 (unsigned)var
转换为 unsigned long
或无符号整型
?
最佳答案
根据 C 标准(6.7.2 类型说明符,p.#2)
- ...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/