Assignment of Different Sizes Portability

1
2
3
4
uint32_t variable32 = 32;
uint64_t variable64 = 0;

variable64 = variable32;


Will variable64 have the same value on both little-endian and big-endian platforms?

On little-endian platforms, variable32 would look like this:
20 00 00 00

Then to assign it to a 8-byte variable it would just assign the first four bytes of variable32 to the first four bytes of variable64.
20 00 00 00 00 00 00 00

But on big-endian platforms, will it do the same thing or will it intelligently assign it to the correct place? i.e.:
00 00 00 20 00 00 00 20 00 00 00 00

as opposed to:

00 00 00 20 00 00 00 00 00 00 00 20
Last edited on
yes.
Topic archived. No new replies allowed.