Bug 78008 - Forbid or document #pragma pack(0)
Summary: Forbid or document #pragma pack(0)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, documentation
Depends on:
Blocks:
 
Reported: 2016-10-17 11:20 UTC by dhekir
Modified: 2021-12-19 09:58 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dhekir 2016-10-17 11:20:33 UTC
The GCC online doc (https://gcc.gnu.org/onlinedocs/gcc/Structure-Layout-Pragmas.html) says that #pragma pack is supported for compatibility with MS compilers.

However, the MSVC doc (https://msdn.microsoft.com/en-us/library/2e70t5y1.aspx) explicitly states that, for pack(n): "Valid values are 1, 2, 4, 8, and 16."

Indeed, writing #pragma pack(0) and compiling (with VS 2010, in my case) results in a warning:

warning C4086: expected pragma parameter to be '1', '2', '4', '8', or '16'

On GCC (I tried 5.4.0, but it seems not to have changed in quite some time), using #pragma pack(0) results in no warnings, even with -Wall.

I found very old discussions (around gcc 2.9.5) mentioning that pack(0) is supposed to disable the effect of #pragma pack, however this is not documented.  If the intended behavior is the same as "#pragma pack()" (without arguments), please document it. Otherwise, it would be best if GCC would report this construction as a warning/error, or at least indicate in the documentation that it should not be used.
Comment 1 Andrew Pinski 2021-12-19 09:58:14 UTC
Confirmed.