avidyalalala / sunpinyin

Automatically exported from code.google.com/p/sunpinyin
0 stars 0 forks source link

enforce "packed" on all on-disk data structures which are assumed to be protable across arch of the same endianness #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
we are practically using bit field in all on-disk structures, and ensure that
 - the fields do not cross the boundary of 32 bits.
 - the size of these structures is multiple of 32.

but in theory, the size and in-memory layout of structures is
implementation-dependent.

In the case of GCC, the layout is up to:
 1. the word size of the target architecture
 2. the largest member variable's size
 3. if the member variable crosses the boundary of 32 bits

I checked GCC 4.3 on both amd64 and i386, and it seems we are safe as long
as user compiles sunpinyin with a decent GCC on these arch.

shall we add "__attribute__ ((packed))" at the end of persistent structures
with macro something like following? 

#ifdef __GNUC__
#define PACKED __attribute__ ((packed))
#else
#define PACKED
#endif

Original issue reported on code.google.com by find...@gmail.com on 28 Feb 2010 at 4:22

GoogleCodeExporter commented 9 years ago

Original comment by tchai...@gmail.com on 1 Mar 2010 at 5:44

GoogleCodeExporter commented 9 years ago

Original comment by find...@gmail.com on 1 Mar 2010 at 9:36