Is the binary representation of native types guaranteed to be the same for all purposes?

I plan to store my data in binary format as a resource, read it in the int buffer and basically pass it directly to the built-in C ++ function, which can pass it to the structure / class and work with it. There are no pointers, obviously, just ints and floats.

The question is, what do I need to do to fix it? I suppose I need to check ByteOrder.nativeOrder(), find out if it has a large endian or little endian, and perform a byte replacement if necessary.

Additionally, are floating functions expected in the IEEE 754 format? Are there any other reservations that I completely ignore here?

(Also, since I'm compiling using NDK, I know what architecture is already there (ARMv7-A, in my case), so that I can technically skip the final shenians and just take the data as it is?)

+3
source share
1 answer

ARM supports both large and small endian. This will most likely be installed by the OS, so it might be worth checking this in advance.

There is also a problem with filling out the word size in the structure:

struct st
{
  char a;
  int  b;
};

sizeof 8, 5 . , int . 4 , , gcc pack (struct my_packed_struct __attribute__ ((__packed__)) ). , , .

Android Simulator .

+3

Source: https://habr.com/ru/post/1758139/


All Articles