[<prev] [next>] [day] [month] [year] [list]
Message-ID: <c8f4da177546339dfd935ed4f7441a6a@mu-ori.me>
Date: Wed, 19 Jul 2023 14:42:15 +0000
From: "Drew B." <subs@...ori.me>
To: David Laight <David.Laight@...lab.com>
Cc: linux-kernel@...r.kernel.org
Subject: Re: Misbehavior with setsockopt timeval structure with -fpack-struct
enabled
Hi David!
>> #pragma pack(1, push)
>> ...
>> #pragma pack(pop)
> That is M$ C :-)
> For gcc you can use __attribute__((packed))
Noted. I new about things like __attribute__ ((unused)), but forgot
about mentioned above. My thanks!
> You also pretty much never, ever, want to 'pack' a structure
> unless you need to match a 'hardware/protocol structure' that
> has fields that aren't on their natural boundaries.
Straight to the point! That was the reason why I "packed" the things :).
> Everything that uses a structure has to use the same alignment.
> So 'randomly' packing system structures will break things.
And by 'randomly' you mean using the gcc param instead of attribute 'in
place'?
> If you need to make structures portable between architectures
> then add explicit padding to ensure 64bit items are on their
> natural boundaries (as well as byteswapping as necessary).
Frankly speaking, the size of the data is relatively small. And
byteswapping thing is resolved through the union and byte array, so
everything is being sent as a bytearray of known size and then the type
casting thing happens based on the header information.
Kind regards,
Drew.
Powered by blists - more mailing lists