Visual studio 2022 driver ARM64 build is complaining:
warning C4324: 'CMyClass': structure was padded due to alignment specifier
I already listed all include files and all my:
#include <alignN.h>
#include <alignend.h>
are paired and only applies to structs (no classes are wrapped).
I also tried disabling the warning by putting in the include file:
#pragma warning(disable: 4324)
But strangely, it still outputs the warning. I put one in the file with the issue before any includes as well as the top of the main include file everything includes first.
I know I can stop warnings being errors, but is there a way to figure out what's going on?
I even put it in the project properties Disable Specific Warnings
and that warning still shows up.
TIA!!
Visual studio 2022 driver ARM64 build is complaining:
warning C4324: 'CMyClass': structure was padded due to alignment specifier
I already listed all include files and all my:
#include <alignN.h>
#include <alignend.h>
are paired and only applies to structs (no classes are wrapped).
I also tried disabling the warning by putting in the include file:
#pragma warning(disable: 4324)
But strangely, it still outputs the warning. I put one in the file with the issue before any includes as well as the top of the main include file everything includes first.
I know I can stop warnings being errors, but is there a way to figure out what's going on?
I even put it in the project properties Disable Specific Warnings
and that warning still shows up.
TIA!!
The best place to start with compiler warnings is the documentation, in this case for C4324 (structure was padded due to alignment specifier):
Padding was added at the end of a structure because you specified an alignment specifier, such as __declspec(align).
For example, the following code generates C4324:
struct __declspec(align(32)) A
{
char a;
};
There are two courses of action you can take here: you can either ignore the warning or add explicit padding to the structure.
To ignore the warning, you can include the following declaration before the definition of the structure:
#pragma warning(disable: 4324)
struct __declspec(align(32)) A
{
char a;
};
You should additionally restore the warning afterwards to be a good citizen:
#pragma warning(push)
#pragma warning(disable: 4324)
struct __declspec(align(32)) A
{
char a;
};
#pragma warning(pop)
To add explicit padding, add a field at the end of the structure that takes up the remaining alignment size:
struct __declspec(align(32)) A
{
char a;
char padding[31];
};
Either option eliminates the warning.