Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 1.33 KB

File metadata and controls

31 lines (22 loc) · 1.33 KB
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Compiler Warning (level 4) C4841
Compiler Warning (level 4) C4841
05/03/2021
C4841
C4841

Compiler Warning (level 4) C4841

non-standard extension used: compound member designator used in offsetof

Remarks

If you use offsetof(T, m), where m is a compound member designator, the compiler generates a warning when you compile with the /Wall option.

This warning is new in Visual Studio 2017 version 15.3, and is off by default. Use /Wall to enable all warnings that are off by default, or /w14841 to enable C4841 as a level 1 warning. For more information, see Compiler warnings that are off by default. For information on how to disable warnings by compiler version, see Compiler warnings by compiler version.

Example

The following code is ill-formed and could potentially cause a crash at runtime:

struct A {
   int arr[10];
};

// warning C4841: non-standard extension used: compound member designator in offsetof
constexpr auto off = offsetof(A, arr[2]);

To fix the issue, change the code to not use offsetof with a compound member designator.