最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Visual Studio 2022 Driver Build - Warning C4324 - On Class and can't disable? - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论