alignas

gcc over-aligned new support (alignas )

牧云@^-^@ 提交于 2019-12-19 05:43:59
问题 I'm having some difficulty finding more information about GCC's aligned-new warning and the gcc -faligned-new option. Compiling on gcc 7.2.0 (without --std=c++17) and trying to define an aligned struct such as: struct alignas(64) Foo { int x; } Just doing a plain old: Foo * f = new Foo(); Gives me the following warning and suggestion: alignas.cpp:36:25: warning: ‘new’ of type ‘Foo’ with extended alignment 64 [-Waligned-new=] Foo * f = new Foo(); ^ alignas.cpp:36:25: note: uses ‘void* operator

Struggling with alignas syntax

耗尽温柔 提交于 2019-12-08 17:09:22
问题 I am trying to use alignas for pointers that are class members, and frankly I am not sure where I supposed to put it. For instance: class A { private: int n; alignas(64) double* ptr; public: A(const int num) : n(num), ptr(new double[num]) {} }; which I hoped would ensure the data for ptr was aligned on a 64-byte block. Using the Intel compiler, it doesn't. Can anyone point me in the right direction please? 回答1: Using the alignas(N) keyword on a member of a class causes this member to be

Where can I use alignas() in C++11?

吃可爱长大的小学妹 提交于 2019-11-26 22:32:41
In an effort to standardize my code and make it more portable, I replaced #ifdef __GNUC__ typedef __attribute__((aligned(16))) float aligned_block[4]; #else typedef __declspec(align(16)) float aligned_block[4]; #endif with typedef float alignas(16) aligned_block[4]; in C++11. However, gnu (4.8) doesn't like that but complains test.cc:3:9: warning: attribute ignored [-Wattributes] typedef float alignas(16) aligned_block[4]; ^ test.cc:3:9: note: an attribute that appertains to a type-specifier is ignored whereas clang 3.2 creates no warning (even with -Weverything -Wno-c++98-compat -pedantic ).

Where can I use alignas() in C++11?

爷,独闯天下 提交于 2019-11-26 17:27:03
问题 In an effort to standardize my code and make it more portable, I replaced #ifdef __GNUC__ typedef __attribute__((aligned(16))) float aligned_block[4]; #else typedef __declspec(align(16)) float aligned_block[4]; #endif with typedef float alignas(16) aligned_block[4]; in C++11. However, gnu (4.8) doesn't like that but complains test.cc:3:9: warning: attribute ignored [-Wattributes] typedef float alignas(16) aligned_block[4]; ^ test.cc:3:9: note: an attribute that appertains to a type-specifier