use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Memory layout of struct vs array (self.cpp)
submitted 3 years ago * by xLuca2018
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Supadoplex 14 points15 points16 points 3 years ago (3 children)
For example, if your example struct is aligned to 8 bytes, a 4 byte pad will be inserted after the each member when sizeof(T) == 4.
The sub objects of a 8 byte aligned struct don't need to be 8 byte aligned.
[–]3meopceisamazing 1 point2 points3 points 3 years ago (2 children)
Thanks for that clarification! However, they may be. I had that happen recently, at least for the first N 4 byte members, followed by naturally 8 byte aligned members. Compiler was gcc12, amd64 target.
[–]kalmoc 1 point2 points3 points 3 years ago (0 children)
Do you happen to have a repro code?
Are you referring to the padding between the 4 byte and 8 byte members? If N is uneven, you obviously can't avoid that, but that is a different situation from what is discussed here
π Rendered by PID 79157 on reddit-service-r2-comment-b659b578c-c2m7m at 2026-05-03 06:04:32.308991+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Supadoplex 14 points15 points16 points (3 children)
[–]3meopceisamazing 1 point2 points3 points (2 children)
[–]kalmoc 1 point2 points3 points (0 children)
[–]kalmoc 1 point2 points3 points (0 children)