本文介绍了制作GCC和其他C ++编译器非常严格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个大型的协作C ++项目,它是开发和运行在各种风格的Linux,OS X和Windows。我们使用GCC,Visual Studio C ++和Intel C ++编译器在这些平台上编译。随着越来越多的人开始为项目开发代码,我们开始在编译和运行时看到特定的编译器在特定操作系统上的奇怪的错误。一个例子是隐含包含某些操作系统/编译器对似乎找到的头,意外地从派生类中的基类重载一个函数。



我的目标是使GCC的编译更加严格,并在所有平台上捕获更多错误,以便我们不会遇到这些问题。这是我正在考虑尝试GCC的标记列表,我通过谷歌和GCC手册页找到:




  • -Wall

  • -Wextra

  • -Winit-self

  • >
  • -Woverloaded-virtual

  • - 未初始化

  • > -Winit-self

  • -ansi

  • -pedantic


$ b b

人们用来使GCC(而不太重要的是Visual Studio C ++和Intel C ++编译器)遵循更严格的C ++语言标准的其他标志是什么?具体说明你正在谈论的编译器和版本,因为其中一些可能无法在所有编译器的所有版本中实现。

解决方案

除了所有其他人建议的错误,IMO,在编译过程中运行lint总是好的。



有一些工具:




  • (免费)





他们会节省大量的时间。 p>

I'm working on a large collaborative C++ project that is both developed and run on various flavors of Linux, OS X and Windows. We compile across these platforms with GCC, Visual Studio C++ and the Intel C++ compiler. As more and more people start developing code for the project, we're starting to see weird errors in compilation and runtime that are specific to particular compilers on particular operating systems. An example of this is implicit inclusion of headers that certain OS/compiler pairs seem to find for you, accidentally overloading a function from a base class in a derived class.

My goal is to make compilation on GCC more strict and catch more errors across all platforms so that we don't keep running into these problems. Here's my list of flags that I'm thinking about trying out for GCC that I've found via Google and the GCC man pages:

  • -Wall
  • -Wextra
  • -Winit-self
  • -Wold-style-cast
  • -Woverloaded-virtual
  • -Wuninitialized
  • -Wmissing-declarations
  • -Winit-self
  • -ansi
  • -pedantic

What are the other flags that people use to make GCC (and less importantly Visual Studio C++ and the Intel C++ Compiler) obey a stricter standard of the C++ language? Be specific about which compiler and version you're talking about, as some of these might not be implemented in all versions of all compilers.

解决方案

Beside the pedantic-error that everyone else suggested, IMO, it's always good to run lint as part of your compile process.

There are some tools out there:

They will save a lot of your time.

这篇关于制作GCC和其他C ++编译器非常严格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:58