I have a C file:
#include <stdint.h>
typedef struct {
uint32_t m1;
uint16_t m2;
} TStruct;
TStruct s = {
1,
2
};
How to compile this file with gcc to produce little endian binary file?
0x01 0x00 0x00 0x00 0x02 0x00
I have a C file:
#include <stdint.h>
typedef struct {
uint32_t m1;
uint16_t m2;
} TStruct;
TStruct s = {
1,
2
};
How to compile this file with gcc to produce little endian binary file?
0x01 0x00 0x00 0x00 0x02 0x00
Though, Little-Endian is the default for all standard configurations. A otherwise configured compiler toolkit can use this switch to fetch desired format.
gcc file.c -mlittle-endian
There you go..
I guess tying together the other answers. On a little endian machine (x86):
evaitl@evbb ~/se $ cat foo.c
#include <stdint.h>
typedef struct {
uint32_t m1;
uint16_t m2;
} TStruct;
TStruct s = {
1,
2
};
evaitl@evbb ~/se $ gcc -c foo.c
evaitl@evbb ~/se $ objcopy -O binary foo.o foo
evaitl@evbb ~/se $ hexdump -C foo
00000000 01 00 00 00 02 00 00 00 |........|
00000008