ImportC and #pragma pack

Dukc ajieskola at gmail.com
Thu Sep 30 11:52:37 UTC 2021


On Thursday, 30 September 2021 at 00:53:27 UTC, Walter Bright 
wrote:
> Besides, the #pragma pack is never properly documented. For 
> example,
>
>     struct S
>     #pragma pack(1)
>     { ...
>     #pragma pack()
>       ...
>     };
>
> supposed to do? It wretchedly mixes up the preprocessor and the 
> core language syntax in a completely undocumented manner (and 
> they're supposed to be separate languages).

Let's see. Since it's not documented, it'd be unwise to write a 
struct like that. So, if I somehow had a C struct like that, I'd 
want an error. Then I'd move `#pragma pack(1)` either above or 
below the whole struct start depending on what I meant.

Well, there might be some unwritten convention on how the 
compilers handle this but as long as we are not aware of one, 
it's best to do the right thing.


More information about the Digitalmars-d mailing list