For example, I use printf
function in C++ for 8-bit CPU (AVR). Is the following code safe:
uint8_t a = 5;
printf("%d", a);
Here %d
expects int
(16-bit in my case, and at least 16-bit in any case), but I pass 8-bit integer.
Does C/C++ standards guarantee that any type with rank lesser than int
promoted to int
?
The same question for float a
and %f
that expects double
, and other analogous types.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…