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!!
Share Improve this question edited Jan 30 at 2:49 user3161924 asked Jan 30 at 2:19 user3161924user3161924 2,3291 gold badge23 silver badges42 bronze badges 3- stackoverflow/help/minimal-reproducible-example – Luke Commented Jan 30 at 10:10
- If I could reproduce it, I wouldn't need to ask the question. – user3161924 Commented Jan 30 at 22:31
- I'm not sure what that's supposed to mean. If you can't reproduce the issue then it no longer occurs, meaning the problem is solved. But you claim to need to ask the question, implying the problem is not solved and thus can be reproduced. Regardless, I'll do my best to offer an answer despite the lack of almost any specifics in the question. – Luke Commented Jan 31 at 9:50
1 Answer
Reset to default 0The 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.