What's your favorite g++ option? [closed]

2019-03-12 01:19发布

I am a newbie in C++ programming. When compiling I never use any option.

This is my day to day command:

g++ MyCode.cc -o MyCode

For safety practice what's the best option to use?

10条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-12 01:53

-pipe, it speeds up compilation a little bit. Also -O2, which speeds up execution.

查看更多
闹够了就滚
3楼-- · 2019-03-12 01:55
-ansi
-pedantic

-D__STDC_FORMAT_MACROS
-D__STDC_CONSTANT_MACROS
-D__STDC_LIMIT_MACROS
-D_GNU_SOURCE
-D_REENTRANT

-Wall
-Wextra
-Wwrite-strings
-Winit-self
-Wcast-align
-Wcast-qual
-Wold-style-cast
-Wpointer-arith
-Wstrict-aliasing
-Wformat=2
-Wuninitialized
-Wmissing-declarations
-Woverloaded-virtual
-Wnon-virtual-dtor
-Wctor-dtor-privacy
-Wno-long-long

-O3
-ftree-vectorize
-ftree-vectorizer-verbose=2
-ffast-math
-fstrict-aliasing
-march=native/pentium4/nocona/core2
-msse2
-mfpmath=sse
查看更多
三岁会撩人
4楼-- · 2019-03-12 01:58

“-Werror”: treats all warnings as errors so you have to fix them. Incredibly valuable.

查看更多
欢心
5楼-- · 2019-03-12 02:01

We always use

g++ -Wall -Wextra ...
查看更多
登录 后发表回答