Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

3 Answers 3

up vote 7 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
3  
+1, I usually do -Wall -Wextra -Werror -pedantic -std=c++0x :) –  greyfade Jun 30 '11 at 21:25

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

 
discard

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.