2

I am a computer science masters student (Conversion) who has recently been taught C, and is now moving on to learning Java. Alongside Java, I have taken it upon myself to learn C++ as it is going to be necessary for the project I wish to do.

While we were learning C, we were required to ensure that our code always compiled with the following flags

-pedantic -Wall -Wextra -Wfloat-equal -ansi -O2

I learned that using these flags helps you pick up some cases of poor practise and also subtle bugs which might not appear straight away (and some that do) and so makes you a lot more productive.

I was wondering if anybody can recommend for me a general set of flags I should always use when compiling C++ programs? I've only just done the classic 'hello world' program at the time of writing so not much room for bugs. But I'd like to start with good habits...

Ben Wainwright
  • 4,224
  • 1
  • 18
  • 36

2 Answers2

3

I will definitely include initially -Werror which will convert all warnings to error.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
1

For Clang, -Weverything which enables literally all warnings, unlike -Wall.

Then you can explicitly disable (-Wno-...) those that you think are too much. I have usually only about 5 or 10 of them.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157