Linked Questions

2 votes
2 answers
432 views

As the size of empty class is 1 byte but when this empty class is virtually inherited that (on gcc compilers) the answer to sizeof(derived1) is coming out to be 8 byte...,how come this is happening as ...
Anuraag's user avatar
  • 33
1 vote
1 answer
332 views

As far as I know, class and struct data is placed one variable after another, for example: class Foo { int A; char B; float* C; double* D; }; Foo Object; char* ptr = &Object; &...
Avert's user avatar
  • 445
0 votes
0 answers
116 views

I have been debugging this simple c++ program for hours but I cannot figure out why it writes garbage values in to text file. when I use fwrite to write data struct to "users.txt" file it looks like ...
Dan Jay's user avatar
  • 873
1 vote
0 answers
63 views

I have an issue with C++ and VS-2015 with the next structure: struct HEADER { char BRI; char crv_lenght; __int16 crv; char messagetype; }; The size of this structure is 5 bytes, but ...
Jorge Omar Medra's user avatar
2 votes
0 answers
62 views

struct s1 { int a; char b; }; struct s2 { char b; }; struct s3 { char a[3]; }; int main() { s1 obj1; s2 obj2; s3 obj3; cout<<sizeof(obj1)<<endl; // ...
girish's user avatar
  • 65
126 votes
5 answers
74k views

I work with shared memory right now. I can't understand alignof and alignas. cppreference is unclear : alignof returns "alignment" but what is "alignment" ? number of bytes to add for the next block ...
Offirmo's user avatar
  • 20.1k
61 votes
10 answers
60k views

I'm working on a 32-bit machine, so I suppose that the memory alignment should be 4 bytes. Say I have this struct: typedef struct { unsigned short v1; unsigned short v2; unsigned short v3; ...
user avatar
54 votes
7 answers
13k views

Systems demand that certain primitives be aligned to certain points within the memory (ints to bytes that are multiples of 4, shorts to bytes that are multiples of 2, etc.). Of course, these can be ...
Alex Gartrell's user avatar
45 votes
7 answers
7k views

Who decides the sizeof any datatype or structure (depending on 32 bit or 64 bit)? The compiler or the processor? For example, sizeof(int) is 4 bytes for a 32 bit system whereas it's 8 bytes for a 64 ...
Vishal-L's user avatar
  • 1,347
30 votes
2 answers
53k views

I was reading Game Coding Complete 4th edition. There was a topic regarding Memory alignment. In the code below the author says that first struct is really slow because it is both not bit-aligned nor ...
Sourabh Mittal's user avatar
13 votes
6 answers
5k views

Considering the following function : template<typename... List> inline unsigned int myFunction(const List&... list) { return /* SOMETHING */; } What is the most simple thing to put ...
Vincent's user avatar
  • 61.1k
8 votes
2 answers
4k views

I suppose I'm a bit confused as to how exactly optional values are stored. When constructing a class or struct that contains std::optional<T> members, will these members be stored contiguously ...
whitwhoa's user avatar
  • 2,499
12 votes
3 answers
3k views

Let's say I have an array of doubles, is it safe to reinterpret_cast it to an array of structs each containing 4 doubles, with regards to alignment? Consider this example code: double *edges = ...; // ...
sashoalm's user avatar
  • 80.5k
7 votes
3 answers
3k views

Preface: Did my research about struct alignment. Looked at this question, this one and also this one - but still did not find my answer. My Actual Question: Here is a code snippet I created in order ...
MordechayS's user avatar
  • 1,546
4 votes
2 answers
3k views

I already read this question: struct padding in c++ and this one Why isn't sizeof for a struct equal to the sum of sizeof of each member? and I know this isn't standardized but still I believe it'...
Dean's user avatar
  • 7,034

15 30 50 per page