Oop, silly me, I didn't read your full question.
For a struct of two ints, I doubt the struct will be larger. However, in general, a struct can end up larger than its component types due to
alignment. TL;DR for performance reasons, variables larger than one byte often need to have addresses that are a multiple of some (power of two) value. For structs, this can mean an awful lot of unused bits to make sure the alignments of their member variables stay consistent with what they'd be outside of a struct.
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
struct Paddington {
char a;
int b;
} test;
int main() {
std::cout << sizeof(test) << " vs " << sizeof(int)+sizeof(char) << "\n";
}
|
Structs may also be padded at the end based on the alignment needs of its member variables. In this case, you could swap the positions of a and b in the struct, and the struct's size would still be 8.
EDIT:
#if 1
is
arcane heresy in the age of C++17 a preprocessor statement, much like #include. Here's some light reading on them:
http://www.cplusplus.com/doc/tutorial/preprocessor/#conditional_inclusions
TL;DR the stuff between an #if and the next #elif, #else, or #endif only gets compiled if the condition of the #if is true (and 1 is true). This means dhayden has a single line that he can change one character in to switch whether the following code uses an std::array or C-style array.
-Albatross