diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4324.md b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4324.md index f2f4076e29a..0d36a85e2ca 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4324.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4324.md @@ -1,27 +1,49 @@ --- -description: "Learn more about: Compiler Warning (level 4) C4324" title: "Compiler Warning (level 4) C4324" -ms.date: "11/04/2016" +description: "Learn more about: Compiler Warning (level 4) C4324" +ms.date: 07/22/2025 f1_keywords: ["C4324"] helpviewer_keywords: ["C4324"] --- # Compiler Warning (level 4) C4324 -> '*structname*': structure was padded due to alignment specifier +> '*type*': structure was padded due to alignment specifier + +## Remarks -Padding was added at the end of a structure because you specified an alignment specifier, such as [__declspec(align)](../../cpp/align-cpp.md). +Padding was added at the end of a class/struct/union because you specified an alignment specifier, such as [`alignas`](../../cpp/alignas-specifier.md) or [`__declspec(align)`](../../cpp/align-cpp.md). -For example, the following code generates C4324: +## Example + +For example, `S1`, `U1`, and `C1` generate C4324 because padding is added when the specified alignment is greater than the natural alignment for each. `S2` doesn't generate a warning because the specified alignment matches the natural alignment: ```cpp // C4324.cpp -// compile with: /W4 -struct __declspec(align(32)) A +// compile with: /W4 /c + +// natural 4 byte alignment +struct alignas(8) S1 // C4324 { - char a; + int i; }; // C4324 -int main() +// natural 4 byte alignment +struct alignas(4) S2 +{ + int i; +}; // OK + +// natural 4 byte alignment +union alignas(16) U1 +{ + int i; + char c; +}; // C4324 + +// natural 4 byte alignment +class alignas(8) C1 { -} +public: + int i = 0; +}; // C4324 ``` diff --git a/docs/error-messages/compiler-warnings/compiler-warnings-c4200-through-c4399.md b/docs/error-messages/compiler-warnings/compiler-warnings-c4200-through-c4399.md index 08698aef3ad..e2115eba561 100644 --- a/docs/error-messages/compiler-warnings/compiler-warnings-c4200-through-c4399.md +++ b/docs/error-messages/compiler-warnings/compiler-warnings-c4200-through-c4399.md @@ -113,7 +113,7 @@ The articles in this section describe Microsoft C/C++ compiler warning messages |Compiler warning (level 1) C4321|automatically generating an IID for interface '*interface*'| |Compiler warning (level 1) C4322|automatically generating a CLSID for class '*class*'| |Compiler warning (level 1) C4323|re-using registered CLSID for class '*class*'| -|[Compiler warning (level 4) C4324](compiler-warning-level-4-c4324.md)|'*structname*': structure was padded due to alignment specifier| +|[Compiler warning (level 4) C4324](compiler-warning-level-4-c4324.md)|'*type*': structure was padded due to alignment specifier| |[Compiler warning (level 1) C4325](compiler-warning-level-1-c4325.md)|attributes for standard section '*section*' ignored| |[Compiler warning (level 1) C4326](compiler-warning-level-1-c4326.md)|return type of '*function*' should be '*type1*' instead of '*type2*'| |Compiler warning C4327|'*assignment*': indirection alignment of LHS ('*alignment1*') is greater than RHS ('*alignment2*')|