atomic <udt>对齐到字长

时间:2018-06-27 21:37:04

标签: c++ visual-studio alignment atomic

我的结构如下:

#define _ENABLE_ATOMIC_ALIGNMENT_FIX

#ifdef _WIN32
    struct alignas(4) s {
        uint16_t a;
        uint16_t b;
        uint16_t c;
        uint8_t d;
        uint8_t e;
    };
#else
    struct alignas(8) s {
        uint16_t a; 
        uint16_t b;
        uint16_t c;
        uint8_t d;
        uint8_t e;
    };
#endif // _WIN32

这应该在64位linux机器上运行,因此我试图构建一个64位的结构,该结构可能是原子的,并且由于它具有字长,因此将是无锁的。但是,我正在32位Windows计算机上对此进行编码和测试。 Visual Studio 2015(更新3)始终会引发以下错误:

2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\atomic(519): error C2719: '_Right': formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(525) : error C2719 : '_Right' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(542) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(548) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(580) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(587) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(594) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(602) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(610) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(617) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(624) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(632) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(640) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(647) : error C2719 : '_Value' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(680) : error C2719 : '_Val' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(686) : error C2719 : '_Right' : formal parameter with requested alignment of 8 won't be aligned
2>C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\include\atomic(691) : error C2719 : '_Right' : formal parameter with requested alignment of 8 won't be aligned

我尝试在Windows中使用alignas(8),但仍然无法编译。我不明白为什么编译器无法与必填字段保持一致。如果删除alignas标签,则会出现相同的错误。

谢谢!

0 个答案:

没有答案