2010-01-23 56 views
6

我在Linux上使用gcc 4.4.2用c89和c99編譯gcc 4.4.2默認爲c99嗎?

我只是想知道gcc是否自動默認編譯爲c99作爲其最新的標準?

如何指定我是否想用c89或c99進行編譯?

非常感謝任何建議,

+2

默認值依然gnu89(即C89和GNU擴展)。 –

回答

9

一個理由不使用默認C99是因爲這個標準是不是完全在編譯器實現的呢。不過,我相信你可以在編譯gcc時設置默認模式,所以如果標準的選擇對你真的很重要,最好總是通過選項。

選項分別爲-std=c99-std=c89

+0

我通常使用c89進行編譯,因爲它更便於攜帶。但是我喜歡c99的一些功能。但是,我不能使用c99標準,因爲我需要在使用VS的windows上編譯,而VS只支持c89。即使最新版本的VS 2010也不會實現c89。 – ant2009

+0

如果我檢查[GCC C99status](https://gcc.gnu.org/c99status.html),我找不到任何會影響大多數用例的缺失功能。你可以舉一個可以阻止使用C99編譯的缺失功能的例子嗎? –

+0

@RuudAlthuizen這個答案是在2010年編寫的。截至2016年,據我所知,只有浮點專家方面缺失。 「中的浮點環境訪問」被標記爲「庫特性,不需要編譯器支持」,但實際上這肯定**需要編譯器支持,而GCC不提供這種支持。 –

9

gcc(1)手冊頁:

-std= 
     Determine the language standard. This option is currently only 
     supported when compiling C or C++. 

.... 

     c99 
     c9x 
     iso9899:1999 
     iso9899:199x 
      ISO C99. Note that this standard is not yet fully supported; 
      see <http://gcc.gnu.org/gcc-4.4/c99status.html> for more 
      information. The names c9x and iso9899:199x are deprecated. 

     gnu89 
      GNU dialect of ISO C90 (including some C99 features). This is 
      the default for C code. 

     gnu99 
     gnu9x 
      GNU dialect of ISO C99. When ISO C99 is fully implemented in 
      GCC, this will become the default. The name gnu9x is 
      deprecated.