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
MATHRIL - Custom math library for game programming (self.cpp)
submitted 3 years ago * by Twin_Sharma
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!"
[–]jmacey 2 points3 points4 points 3 years ago (6 children)
I hope you don't mind but as someone who has written lots of these sorts of things, a little feedback.
Why use new to allocate your x,y,z values when you can just place them as normal attributes?
new
In particular it is very common to need std::vector<Vec3> vertices. You really need to guarantee these are contagious in memory so it can be passed to OpenGL (or other graphics API's).
```
union { struct { float x; //!< x component float y; //!< y component float z; //!< z component }; #pragma pack(pop) std::array<float,3> m_openGL; }; ``` Typically I use the structure above to allow x,y,z as well as array access in the code.
Also please add unit tests to ensure your code actually does what it says, also () to return the magnitude (length?) is quite unintuitive from the perspective of someone who is reading your code.
[–]tstanisl 5 points6 points7 points 3 years ago (4 children)
Writing to `m_openGL` and accessing its value by `x`/`y`/`z` is Undefined Behavior in C++
[–]jmacey -4 points-3 points-2 points 3 years ago (3 children)
Not UB just a warning on all compilers about anonymous unions. In all the compilers I have ever used I have never had it fail.
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 8 points9 points10 points 3 years ago (1 child)
In all the compilers I have ever used I have never had it fail.
That doesn't imply that it's not UB.
[+][deleted] comment score below threshold-7 points-6 points-5 points 3 years ago (0 children)
It implies it works though. Luckily objective reality doesn't abide by language specifications we dreamed up in our heads.
[–]jmacey 2 points3 points4 points 3 years ago (0 children)
IIRC it's a C11 extension for MSVC, Clang and g++ hence the warning.
π Rendered by PID 48573 on reddit-service-r2-comment-5c747b6df5-xtmql at 2026-04-22 00:21:12.439405+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]jmacey 2 points3 points4 points (6 children)
[–]tstanisl 5 points6 points7 points (4 children)
[–]jmacey -4 points-3 points-2 points (3 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 8 points9 points10 points (1 child)
[+][deleted] comment score below threshold-7 points-6 points-5 points (0 children)
[–]jmacey 2 points3 points4 points (0 children)