My code looks like this:
#include <stdio.h>
#pragma pack(1)
class MyClass
{
bool a;
bool b;
int c;
char d[3];
bool e[4];
};
#pragma pack()
int main()
{
printf("sizeof(MyClass)=%d\n", sizeof(MyClass));
return 0;
}
The output is:
sizeof(MyClass)=13
But when I "hover" over sizeof(MyClass) I get:

This wouldn't have been a big issue but I'm trying to implement a compile-time assertion and it isn't working (getting a red underline):

Anyone have any idea how to fix this?
This is not a difference between compile-time and run-time; it is a difference between your compiler and your IDE's "intellisense", the latter of which appears not to support/recognise the #pragma pack directive.
Ignore it. The size is 13.
Since you can actually build your program, you know that the compile-time assertion succeeds, despite the "red line".
It is probably worth adding a comment before that assertion, explaining that users of Visual Studio 2015 will see a false negative in their IDE for the following assertion.
You may also wish to raise a bug on Microsoft Connect, if there is not one already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With