alignas is an attribute introduced in C++11, which informs the compiler that the attributed object shall have a certain memory alignment. It replaces non-portable, compiler-specific alignment attributing, such as __declspec(align(16)).
Questions tagged [alignas]
37 questions
0
votes
1 answer
error: storage class may not be specified here when using __align() in MDK ARM uVision v5 ARM Compiler 5
I am migrating a project from CubeIDE (GCC) to the most comprehensive software development solution for Arm®-based microcontrollers uVision (ARM Compiler 5) and have a difficulty using __align keyword.
CubeIDE code which compiles fine in…

Joej
- 1
- 2
0
votes
1 answer
assert that struct type is declared with alignas()
As the title states, I need some way to assert that a type has been declared with alignas as such:
struct alignas(16) MyStruct {
...
};
It is meant to be used for a template parameter where the template class needs to make sure that the type it…

Tegon McCloud
- 63
- 1
- 6
0
votes
0 answers
Array of aligned structure that induces a regular array of individual members
If I have an structure (e.g. employee below), an array of such structure induces strided arrays of all the members of the structure only if the size of the structure is a (least) common multiple (LCM) of the size all members.
Otherwise there will…

alfC
- 14,261
- 4
- 67
- 118
0
votes
0 answers
Alignment of Member Array in Class not Working
I use the following to 16-byte align a 4 element float array in a class
class Foo
{
// ... some code
private:
alignas(16) float array[4];
};
The variable is not aligned. Why is that? My assumption would be that the alignment depends on…

ruhig brauner
- 943
- 1
- 13
- 35
0
votes
2 answers
Expected primary-expression before `alignas(X)`?
I want to test the use of alignas(), so I write down these code:
#include
using namespace std;
template
void user(const vector& vx)
{
constexpr int bufmax = 1024;
alignas(X) buffer[bufmax];
const int max =…

Shangchih Huang
- 319
- 3
- 11
0
votes
1 answer
"natural_alignment_of" type_trait?
In C++11, we now have the alignas keyword, which can be used to define a new type that is simply an existing type, but with stricter alignment, for example by typedef:
typedef char Maximally_Aligned_Char alignas( max_align_t );
Is there a way…

Charles L Wilcox
- 1,126
- 8
- 18
-1
votes
1 answer
warning: memcpy forming offset [X, Y] is out of the bounds [0, 2] of object Z
I'm trying to assemble information in a struct to later memcopy it to an spi buffer. This is the code I'm working with:
Demo
#include
#include
#include /* memcpy */
using data_settings = uint8_t;
enum class…

glades
- 3,778
- 1
- 12
- 34