>
> Unless the on disk format is carried over into memory, there's no
> reason not to use a structure alignment which prevents unaligned
> access.
>
> I'm a little surprised your compiler hadn't already padded the struct
> out to proper alignment when you built SQLite.
>

Sorry, I'm a little bit lost here. Maybe I mis-explained something -
maybe due to my non-native English. Sorry for that. Let's re-iterate
through my problem once again.

My compiler does have right padding. By default, almost all compilers
will align structure members on natural alignment boundary, which
means align a member on the offset which is a multiple of the member
data size.

In my case it is array of chars that has got mis-aligned. To be
precise, it is aligned just right to store 1, 2, 4, 8 size types
there, but it is not aligned properly for 16-byte long double. For
this case, #pragma pack, which is more or less portable (I really like
this 'more or less portable' - crazy world, you've gone too far...),
won't work because it allows only to pack - that is, to lower
alignment boundaries - it is used when you need to pack structures for
network transfer, for example. And in fact, #pragma pack can only make
hardware alignment issues only worse.

So the only (known so far) portable way to fix the problem is to union
the problematic array with long double variable to get it aligned
properly - on 16-bytes boundary. On GCC we could also use

__attribute__ ((aligned (16)))

but it is not portable.

Please don't hesitate to ask for clarifications if something is not
clear here - I really want to follow it up ASAP.

--
Alexei Alexandrov

Reply via email to