Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning C++ and I'm using g++ on Linux for practicing.

  1. I want to know if people working as programmers use g++ -pedantic flag and also its importance in real world.

  2. What about other compilers, do they also allow this? Has this become some de-facto standard?

I'm interested because I'm reading C++ Primer where the author points that it’s illegal to use non-const expression as dimension in array definition and g++ by default allows it. And there might be other things I'm unaware of.

share|improve this question
@Chris - this is a good fit for Programmers. There's not a specific coding problem to be solved here. The OP needs more information on compiler flags. – ChrisF Jun 30 '11 at 21:57
Fair enough, I stand corrected. – Chris Jun 30 '11 at 22:24
Related question on SO: What is the purpose of using -pedantic in GCC/G++ compiler? – Ivan Chau Dec 17 '13 at 1:33
up vote 10 down vote accepted

Yes, absolutely do this. In fact, you need to study the manual page and turn on more warnings than -pedantic and -Wall will do.

No, there's no standard. MSVC uses /W4 for example.

share|improve this answer
+1, I usually do -Wall -Wextra -Werror -pedantic -std=c++0x :) – greyfade Jun 30 '11 at 21:25
@greyfade Do you use -Wall -Wextra -Werror -pedantic -std=c++11 now? – Jared Burrows May 10 '15 at 18:00
@JaredBurrows: Actually I've stopped using -pedantic with C++ since GCC's manual implies it's only meant for C, and I've moved up to using -std=c++14 in new projects. – greyfade May 10 '15 at 21:39
@greyfade Ah, I should have said, -Wall -Wextra -Werror -std=c++14 :) – Jared Burrows May 10 '15 at 22:03
@VillasV Well -Werror turns all warnings into errors. But -pedantic-errors only makes errors out of Standard ICO C++ violations. – Galik Feb 15 at 15:21

While I have not programmed C++ for quite some time, I'd advise you to use this flag. It helps you creating standards-compliant code and will make everyone's life easier. AFAIK, most other compilers don't support the gcc/g++ extensions.

I hate it for example, when I can't compile code just because the original developer decided to code against non-standard compiler extensions.

I bet that a huge quantity (let's say 20%) of linux programs that were written in C/C++ won't compile with anything but gcc/g++, which makes me kinda sad. Always adhere to the standards.

share|improve this answer
The last time I tried using other compilers, I'd say it was more like 20% that would work with other compilers, and 80% depended on gcc extensions. – Jerry Coffin Jun 30 '11 at 22:45

Personally I use:

-Wall -Wextra -Wshadow -Weffc++ -Wstrict-aliasing -ansi -pedantic -Werror

Thus turns on a host of warnings, but more importantly treats all warnings as errors (as most warnings are logical errors in your thinking).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.