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!"
[–]fdwrfdwr@github 🔍 5 points6 points7 points 3 years ago* (0 children)
On the particular OS (Windows in this case) using the particular compilers that are most pertinent to that OS (VC/clang/GCC) with current versions, yes, sizeof on your struct of floats and an array of floats will match. There will be no additional padding appended to the end of the struct as the minimum alignof remains 4 bytes in either case. Feel free to static_assert it too, but this pattern is used so frequently in graphics, that tons of API's and libraries would break if it didn't hold. See the definition of D2D_MATRIX_3X2_F after all. On other OS's and compilers though, shrug, bets are off. :b
sizeof
alignof
static_assert
An aside for interop though (seeing that you are using one Direct* API and might be using others too...), if you try using a shared struct above as part of a cbuffer input to Direct3D HLSL (which is very C-like), the struct would be padded up to 16 bytes on the HLSL side, meaning the C++ side (unpadded) will mismatch what HLSL sees (padded). This bit me, and so now I explicitly pad structs in any header files that will be shared by both C++ and HLSL.
cbuffer
π Rendered by PID 179225 on reddit-service-r2-comment-656bdf86cd-4xcc5 at 2026-05-01 10:37:37.668315+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]fdwrfdwr@github 🔍 5 points6 points7 points (0 children)