Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the current #pragma pack setting in C++?

Here is an example how to set the current #pragma pack:

#pragma pack(4)

How is it possible to show the current #pragma pack setting?

like image 680
BlueTune Avatar asked Oct 17 '25 13:10

BlueTune


2 Answers

With Microsoft's C++ compiler you can use

#pragma pack(show)

which causes the compiler to issue a warning containing the value.

Note this is not standard C++ (and neither is any guise of #pragma pack) so other compilers may or may not have this feature. At the time of writing GCC, for example, doesn't.

like image 79
Bathsheba Avatar answered Oct 20 '25 02:10

Bathsheba


For Microsoft Visual C++ use

#pragma pack(show)

It will generate the following compiler warning:

Warning C4810   value of pragma pack(show) == 4
like image 45
BlueTune Avatar answered Oct 20 '25 04:10

BlueTune



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!