cochran_emc.h: packed structs

Lubomir I. Ivanov neolit123 at gmail.com
Tue Oct 28 08:39:27 PDT 2014


On 28 October 2014 17:17, Thiago Macieira <thiago at macieira.org> wrote:
> On Tuesday 28 October 2014 08:09:20 Dirk Hohndel wrote:
>> On October 28, 2014 8:05:20 AM "Lubomir I. Ivanov" <neolit123 at gmail.com>
> wrote:
>> > On 28 October 2014 16:28, Dirk Hohndel <dirk at hohndel.org> wrote:
>> > > On Tue, Oct 28, 2014 at 01:28:47PM +0200, Lubomir I. Ivanov wrote:
>> > >> } __attribute__((packed));
>> > >> is unreliable with MINGW > 4.6 up until 4.8.2 - the one i have bundled
>> > >> with the Qt 5.3.
>> > >
>> > > Yes, Jef pointed that out (with less detail) on the libdivecomputer
>> > > mailing list.
>> > >
>> > >> padding is added regardless and there is high potential for the code to
>> >
>> > break.
>> >
>> > >> one solution would be to branch / use "#pragma pack()" which is an
>> > >> MSVC thing but recent MINGW supports it.
>> > >>
>> > >> i'm CCing John Van Ostrand as the author, and posting this message so
>> > >> that everyone knows.
>> > >> perhaps there is a need for a SUBSURFACE_PACK_STRUCT(x) macro of sorts.
>> > >
>> > > Is there a reliable way to do packed structures with mingw, msvc and
>> > > gcc?
>> > > If yes then I would love to have such a macro (or however this would be
>> > > done).  Being able to do this would make code so much more readable.
>> > >
>> > > We might even convince Jef to allow use of such a construct (after it's
>> > > sufficiently tested) in libdivecomputer which would do wonders for my
>> > > sanity :-)
>> >
>> > here is a solution (found online) that uses 'gcc_struct'.
>> > the attribute itself exists since 3.4.x.
>> > by coupling with 'packed' it respects the forced packing - tested on
>> > mingw 4.8.2!
>> > 'packed' not working in general still remains a bug...
>> >
>> > something to note - in the manual, they do not mention if it exists
>> > for GCC-ARM, but i would assume it does.
>> > also i have no idea if clang has it.
>>
>> I can test clang. What about msvc?
>
> __declspec(packed)
>

i don't have that in MSVC 2003; perhaps it's a newer feature.

this works:
#pragma pack(1)
...
#pragma pack()

or this:
#pragma pack(push, 1)
...
#pragma pack(pop)


lubomir
--


More information about the subsurface mailing list