Is the following kind of code safe?
Yes, it is.
So do you know the type and size (by that I mean on how much bytes is it stored) of hard-coded "0x03000000" ?
0x03000000
is int
on a system with 32-bit
int
and long
on a system with 16-bit
int
.
(As uint32_t
is present here I assume two's complement and CHAR_BIT
of 8
. Also I don't know any system with 16-bit
int
and 64-bit
long
.)
Is it possible that some systems consider 0x03000000 as an int and hence code it only on 2 bytes, which would be catastrophic?
See above on a 16-bit
int
system, 0x03000000
is a long
and is 32-bit
. An hexadecimal constant in C is the first type in which it can be represented:
int
, unsigned int
, long
, unsigned long
, long long
, unsigned long long