From 95ee0740fbfb76c7e33c7d13f95b20d5dba37bde Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:03:12 +0800 Subject: [PATCH 1/9] Add "Remarks" and "Example" headings in C4324 warning reference --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 4 ++++ 1 file changed, 4 insertions(+) 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..883f7ca1807 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 @@ -9,8 +9,12 @@ helpviewer_keywords: ["C4324"] > '*structname*': 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). +## Example + For example, the following code generates C4324: ```cpp From 51f5892904b1f11563cb5043114be9359732d9d6 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:11:30 +0800 Subject: [PATCH 2/9] Update C4324 warning message --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 2 +- .../compiler-warnings/compiler-warnings-c4200-through-c4399.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 883f7ca1807..3d6858e59f8 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 @@ -7,7 +7,7 @@ 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 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*')| From f0aa1f53a5862e26692355fc13af9903abe2b13f Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:16:55 +0800 Subject: [PATCH 3/9] Add details to remarks in C4324 warning reference --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3d6858e59f8..a7bb362f2e7 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 @@ -11,7 +11,7 @@ helpviewer_keywords: ["C4324"] ## 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). ## Example From ebbeb2497c913f46ba5fee01725f235614d718a5 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:37:23 +0800 Subject: [PATCH 4/9] Improve example in C4324 warning reference --- .../compiler-warning-level-4-c4324.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 a7bb362f2e7..effab81827e 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 @@ -15,17 +15,21 @@ Padding was added at the end of a class/struct/union because you specified an al ## Example -For example, the following code generates C4324: +For example, `S1` and `S2` generates C4324 because padding is added when the specified alignment is greater than the default alignment of `1` and `4` respectively: ```cpp // C4324.cpp -// compile with: /W4 -struct __declspec(align(32)) A +// compile with: /W4 /c + +struct alignas(4) S1 {}; // C4324 + +struct alignas(8) S2 { - char a; + int i; }; // C4324 -int main() +struct alignas(4) S3 { -} + int i; +}; // OK ``` From 683a6350d2623b00fa8a88c08c58e37489632715 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:38:21 +0800 Subject: [PATCH 5/9] Update metadata in C4324 warning reference --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 effab81827e..5aed86571e3 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,7 +1,7 @@ --- -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"] --- From 8e05527d04f8029e6bf99983b2ec96c8ad5569b2 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Mon, 23 Feb 2026 14:58:56 -0800 Subject: [PATCH 6/9] expand on example --- .../compiler-warning-level-4-c4324.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 5aed86571e3..412a1180f29 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 @@ -21,13 +21,23 @@ For example, `S1` and `S2` generates C4324 because padding is added when the spe // C4324.cpp // compile with: /W4 /c -struct alignas(4) S1 {}; // C4324 - -struct alignas(8) S2 +struct alignas(8) S1 // C4324 { int i; }; // C4324 +union alignas(16) U1 +{ + int i; + float f; +}; // C4324 + +class alignas(8) C1 +{ +public: + int i = 0; +}; // C4324 + struct alignas(4) S3 { int i; From e66f1cef419c2e093375e03d03be2120ba1a9c80 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Mon, 23 Feb 2026 15:01:09 -0800 Subject: [PATCH 7/9] Clarify example for compiler warning C4324 --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 412a1180f29..d5643369a70 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 @@ -15,7 +15,7 @@ Padding was added at the end of a class/struct/union because you specified an al ## Example -For example, `S1` and `S2` generates C4324 because padding is added when the specified alignment is greater than the default alignment of `1` and `4` respectively: +For example, `S1`, `S2`, `U1`, and `C1` generate C4324 because padding is added when the specified alignment is greater than the default alignment for each: ```cpp // C4324.cpp From 57ba3227feadeb739d4b2e61566c424e9905fd86 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Mon, 23 Feb 2026 15:11:58 -0800 Subject: [PATCH 8/9] Fix alignment description in C4324 warning example expanded the example --- .../compiler-warning-level-4-c4324.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 d5643369a70..e26ff5d09b0 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 @@ -15,31 +15,35 @@ Padding was added at the end of a class/struct/union because you specified an al ## Example -For example, `S1`, `S2`, `U1`, and `C1` generate C4324 because padding is added when the specified alignment is greater than the default alignment for each: +For example, `S1`, `U1`, and `C1` generate C4324 because padding is added when the specified alignment is greater than the nautral alignment for each. `S2` doesn't generate a warning because the specified aligment matches the natural alignment: ```cpp // C4324.cpp // compile with: /W4 /c +// natural 4 byte alignment struct alignas(8) S1 // C4324 { int i; }; // C4324 +// natural 4 byte alignment +struct alignas(4) S2 +{ + int i; +}; // OK + +// natural 4 byte alignment union alignas(16) U1 { int i; - float f; + char c; }; // C4324 +// natural 4 byte alignment class alignas(8) C1 { public: int i = 0; }; // C4324 - -struct alignas(4) S3 -{ - int i; -}; // OK ``` From 3823f9fd0f6d09688b1b79befa15f4f7b9122b8a Mon Sep 17 00:00:00 2001 From: Tracey Torble <56347952+ttorble@users.noreply.github.com> Date: Tue, 24 Feb 2026 15:19:19 +0000 Subject: [PATCH 9/9] Update docs/error-messages/compiler-warnings/compiler-warning-level-4-c4324.md --- .../compiler-warnings/compiler-warning-level-4-c4324.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e26ff5d09b0..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 @@ -15,7 +15,7 @@ Padding was added at the end of a class/struct/union because you specified an al ## Example -For example, `S1`, `U1`, and `C1` generate C4324 because padding is added when the specified alignment is greater than the nautral alignment for each. `S2` doesn't generate a warning because the specified aligment matches the natural alignment: +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