编译器不会警告 C 数据丢失或精度丢失
C loss of data or precision is not warned about by compiler
Apple 的 LLVM 不会就此问题发出警告,即使指定了 -Wall
:
uint8_t tta;
typedef uint32_t TT;
TT ttb;
ttb= 0xdeadbeef;
tta = ttb;
// here tta is only 0xEF
如何强制编译器在赋值期间警告数据丢失?
如果您使用 -Wconversion
,您会收到警告:
<stdin>:9:7: warning: implicit conversion loses integer precision: 'TT' (aka 'unsigned int') to 'uint8_t' (aka 'unsigned char') [-Wconversion]
tta = ttb;
~ ^~~
1 warning generated.
这是由 Apple 开发者工具的当前发行版生成的:
Apple LLVM version 8.1.0 (clang-802.0.42)
Apple 的 LLVM 不会就此问题发出警告,即使指定了 -Wall
:
uint8_t tta;
typedef uint32_t TT;
TT ttb;
ttb= 0xdeadbeef;
tta = ttb;
// here tta is only 0xEF
如何强制编译器在赋值期间警告数据丢失?
如果您使用 -Wconversion
,您会收到警告:
<stdin>:9:7: warning: implicit conversion loses integer precision: 'TT' (aka 'unsigned int') to 'uint8_t' (aka 'unsigned char') [-Wconversion]
tta = ttb;
~ ^~~
1 warning generated.
这是由 Apple 开发者工具的当前发行版生成的:
Apple LLVM version 8.1.0 (clang-802.0.42)