I have a struct, which needs to be packed (without packing the size is 20 bytes, but I need 16 to be able to read/write it). When I added the packed attribute I got error: packed attribute is unnecessary for
warnings for all the members of the struct. When silencing the error with the pragmas, the code compiles fine and the size of the struct is 16, but if I remove the pragmas it fails (since I'm using -Werror
). Is clang just issuing this warning incorrectly or am I doing something wrong?
#include <cstdint>
typedef struct __attribute__((packed))
{
uint16_t wFormatTag;
uint16_t nChannels;
uint32_t nSamplesPerSec;
uint32_t nAvgBytesPerSec;
uint16_t nBlockAlign;
}
WAVEFORMAT;
int main()
{
WAVEFORMAT w;
(void)w;
}
I am using the Xcode9 toolchain:
clang -v
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Which generates the warning when compiled with -Weverything
:
clang++ -Weverything pack.cpp
pack.cpp:8:10: warning: packed attribute is unnecessary for 'wFormatTag' [-Wpacked]
WORD wFormatTag;
^
...