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...
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...
Oddson asked 11/6, 2020 at 5:53
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...
1
Solved
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...
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...
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...
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:
...
1
© 2022 - 2024 — McMap. All rights reserved.