I know this article is titled "C compiler flags" but one of the most
underused for C++ is `-D_GLIBCXX_DEBUG` which gives bounds checks on
standard containers. Beginners are particularly prone to this and it
helps a lot.
Maybe it deserves a mention here, it is really unfortunate how lacking
education is here.
Regards,
Re: My favorite C compiler flags during development
Several times now your -D_GLIBCXX_DEBUG suggestion has reminded me to use
it when testing or reviewing a conventional C++ program. Otherwise I would
have forgotten! I'm forming a habit of enabling it automatically alongside
sanitizers to cover the gaps.
Re: My favorite C compiler flags during development
On 2025-01-12 17:48, Christopher Wellons wrote:
> Several times now your -D_GLIBCXX_DEBUG suggestion has reminded me to > use it when testing or reviewing a conventional C++ program. Otherwise > I would have forgotten! I'm forming a habit of enabling it > automatically alongside sanitizers to cover the gaps.
Great! This feature of libstdc++ definitely goes underused.
On a related point, GCC 15 is enabling _GLIBCXX_ASSERTIONS by default
for -O0 builds. That's good progress.
https://gcc.gnu.org/gcc-15/changes.html