Structures on the Raspberry Pi (Debian linux)
Václav Zeman
vhaisman@gmail.com
Mon Jul 2 07:24:00 GMT 2012
On 2 July 2012 08:45, Ray Newman wrote:
> Hi,
>
> I have an implementation of the MUMPS language that has been in use for approx 12 years on the x86 under FreeBSD, linux and OSX.
>
> In the code there is the following structure definition which describes an on disk structure and hence can't really be changed.
>
> typedef struct DB_BLOCK // database block layout
> { u_char type; // block type
> u_char flags; // flags
> u_short spare; // future
> u_int right_ptr; // right pointer
> u_short last_idx; // last used index off
> u_short last_free; // last free lw in block
> chr_q global; // global name
> } DB_Block; // end block header
>
> This structure works OK on the x86 but on the Raspberry Pi, the global element is extracted from the data commencing at global+4 for 8 bytes.
>
> Is there some way to force gcc to have global at +12 and not +16 in the structure?
>
> I tried compiling with the switch -fpack-struct; but this broke the whole thing.
You can apply __attribute__((packed)) on just the structure instead.
See <http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Variable-Attributes.html#index-g_t_0040code_007bpacked_007d-attribute-2667>.
--
VZ
More information about the Gcc-help
mailing list