alignas Questions

2

Solved

The use of aligned_storage is deprecated in C++23 and suggested to be replaced with an aligned std::byte[] (see here). I have two questions about this: 1. How to align this? The document suggests t...
Applecart asked 16/2, 2023 at 18:16

0

Suppose I have the following simple class: struct employee{ std::string name; short salary; std::size_t age; employee(std::string name, short salary, std::size_t age) : name{name}, salary{sal...

1

Solved

This program: struct alignas(4) foo {}; int main() { return sizeof(foo); } returns 4, with GCC 10.1 and clang 10.1, and icc 19.0.1 . That makes me wonder - is it mandatory for alignas() to affe...
Zink asked 17/5, 2020 at 18:29

3

Solved

I am trying to understand how alignas should be used, I wonder if it can be a replacement for pragma pack, I have tried hard to verify it but with no luck. Using gcc 4.8.1 (http://ideone.com/04mxpI...
Basis asked 24/9, 2013 at 9:40

1

Solved

What is the best or conventional method to align members inside a structure? Is adding dummy arrays the best solution? I have a struct of double and a triple of doubles? struct particle{ double ...
Round asked 9/8, 2019 at 5:54

4

Solved

In C one can allocate dynamic arrays using malloc(sizeof(T) * N) and then use pointer arithmetic to get elements at i offset in this dynamic array. In C++ one can do similar using operator new() i...
Iy asked 23/11, 2018 at 18:59

1

Solved

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 st...
Halicarnassus asked 19/3, 2018 at 22:16

2

I want to overalign my type on a cache boundary, so I used alignas: struct alignas(64) W { }; This compiles fine. But then, to my surprise, when I try to allocate a bunch of Ws, they're not 64-b...
Protamine asked 12/2, 2016 at 14:55

1

I am getting unexpected results when running the following code for 32-bit x86 linux (compiler flags: g++ -std=c++14 -m32). I tried gcc and clang. #include <iostream> using namespace std; s...
Typal asked 6/1, 2016 at 13:27

4

Solved

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 ali...
Eolande asked 3/4, 2013 at 13:39

1

Solved

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: ...
Lucie asked 17/12, 2014 at 20:36
1

© 2022 - 2024 — McMap. All rights reserved.