26

我是 C++ 编程的新手。编译时我从不使用任何选项。

这是我的日常命令:

g++ MyCode.cc -o MyCode

对于安全实践,最好的选择是什么?

4

10 回答 10

39
g++ -W -Wall -Werror

将显示所有可能的错误和警告并将它们视为错误。

于 2009-02-20T08:15:11.223 回答
19

“-Werror”:将所有警告视为错误,因此您必须修复它们。无比珍贵。

于 2009-02-20T08:09:49.130 回答
19
g++ -g 

我真的需要那个调试信息....

于 2009-02-20T08:32:54.253 回答
18

如果你认为你抓住了一切,试试-Wextra

于 2009-02-20T08:41:17.120 回答
11
g++ -Wall -Weffc++ -Werror -pedantic

但是,当我使用 Boost 时,我将其归为:

g++ -Wall -Werror

不过,我正在焦急地等待 GCC 4.4 和 4.5。有一些我非常需要的功能即将推出。

于 2009-02-20T08:28:13.313 回答
9
-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
于 2009-03-17T13:07:55.707 回答
8

We always use

g++ -Wall -Wextra ...
于 2009-02-20T22:07:45.637 回答
5

实际上,它是一个集合:-Wall -pedantic -std=c++98

于 2009-02-20T08:10:08.440 回答
4

-pipe,它加快了编译速度。还有-O2,它可以加快执行速度。

于 2009-02-20T10:43:44.987 回答
3

I like -march=athlon -O2 -pipe for building most programs (I run Gentoo at home), and I use -ansi -pedantic -Wall for code I write myself.

于 2009-02-20T14:38:21.240 回答