台灣最大程式設計社群網站
線上人數
2295
 
會員總數:245979
討論主題:189557
歡迎您免費加入會員
討論區列表 >> Linux / Unix >> 編譯需何種參數才會認識"//"單行註解符號?
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
編譯需何種參數才會認識"//"單行註解符號?
價值 : 10 QP  點閱數:3104 回應數:8
樓主

小麥
門外漢
0 8
175 24
發送站內信

作業環境為UNIX~
程式只要打了//單行註解的符號,編譯就會出現錯誤,
錯誤如下:

目前知道只要增加一個參數就可以編譯成功,
但是始終找不到那個參數為何?
我是使用cc來編譯的...
請各位大大幫我解答~~3Q~~

1樓
回應

jack
捐贈 VP 給 怎有人這麼喜歡改暱稱 檢舉此回應
"P"CC 是什麼東西?


gcc 把 -ansi 拿掉 就不會有這種情況發生

try:
-srd=gnu89
or
-std=c99

或是乾脆改用 c++ compile.


man gcc:
.....

-ansi
In C mode, support all ISO C90 programs. In C++ mode, remove GNU extensions
that conflict with ISO C++.

This turns off certain features of GCC that are incompatible with ISO C90
(when compiling C code), or of standard C++ (when compiling C++ code), such as
the "asm" and "typeof" keywords, and predefined macros such as "unix" and
"vax" that identify the type of system you are using. It also enables the
undesirable and rarely used ISO trigraph feature. For the C compiler, it dis-
ables recognition of C++ style // comments as well as the "inline" keyword.

The alternate keywords "__asm__", "__extension__", "__inline__" and
"__typeof__" continue to work despite -ansi. You would not want to use them
in an ISO C program, of course, but it is useful to put them in header files
that might be included in compilations done with -ansi. Alternate predefined
macros such as "__unix__" and "__vax__" are also available, with or without
-ansi.

The -ansi option does not cause non-ISO programs to be rejected gratuitously.
For that, -pedantic is required in addition to -ansi.

The macro "__STRICT_ANSI__" is predefined when the -ansi option is used. Some
header files may notice this macro and refrain from declaring certain func-
tions or defining certain macros that the ISO standard doesn’t call for; this
is to avoid interfering with any programs that might use these names for other
things.

Functions which would normally be built in but do not have semantics defined
by ISO C (such as "alloca" and "ffs") are not built-in functions with -ansi is
used.



-std=
Determine the language standard. This option is currently only supported when
compiling C or C++. A value for this option must be provided; possible values
are

c89
iso9899:1990
ISO C90 (same as -ansi).

iso9899:199409
ISO C90 as modified in amendment 1.

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

gnu89
Default, ISO C90 plus GNU extensions (including some C99 features).

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

c++98
The 1998 ISO C++ standard plus amendments.

gnu++98
The same as -std=c++98 plus GNU extensions. This is the default for C++
code.

Even when this option is not specified, you can still use some of the features
of newer standards in so far as they do not conflict with previous C stan-
dards. For example, you may use "__restrict__" even when -std=c99 is not
specified.

The -std options specifying some version of ISO C have the same effects as
-ansi, except that features that were not in ISO C90 but are in the specified
version (for example, // comments and the "inline" keyword in ISO C99) are not
disabled.
本篇文章回覆於2010-09-29 11:49
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

小麥
檢舉此回應
>>"P"CC 是什麼東西?

我也不太知道"P"是什麼,那行是我執行makefile所跑出來的錯誤。

>>gcc 把 -ansi 拿掉 就不會有這種情況發生

可是我也並沒有加上-ansi參數,而且我是用cc編譯的

大大寫的-std 我就比較看不懂是什麼意思
本篇文章回覆於2010-10-04 13:58
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

vincent
檢舉此回應
dnl
不知道是你要的嗎
本篇文章回覆於2010-10-05 00:01
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
作者回應

小麥
檢舉此回應
感謝三樓大大的回答,但是dnl也不是我需要的答案,

dnl是好像是類似註解一樣的用法,在後面的字都會被視為註解。

我是想要知道

當在C語言中打了


編譯時makefile並不認識"//"這種註解方式

需要在makefile裡增加什麼參數才能編譯過呢?

GOOGLE了很多文章但是卻都找不到我想要的答案,請各位大大幫幫忙。
本篇文章回覆於2010-10-05 15:01
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
5樓
最有價值解答

jack
捐贈 VP 給 怎有人這麼喜歡改暱稱 檢舉此回應
try:
-srd=gnu89
or
-std=c99


你試用過這些參數了嗎?

這些參數 會跟 -ansi 衝突
所以 應該會蓋過你 'P'CC 預設的 -ansi 參數
除非你的 pcc 沒這些參數.....

您要不要找一下 看您的 OS 有沒有提供 'g'cc ??
# which gcc
# whereis gcc
# find / -name "gcc"


有些程式 編譯完後 不是直接在 Linux上跑的
可能有別的 C compile.....
所以問一下
( ex: sdcc for 8051... )
本篇文章回覆於2010-10-07 10:31
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
6樓
作者回應

小麥
檢舉此回應
感謝Jack大大

使用-std=c99才會忽略"//"註解符號的警告

謝謝~~


本篇文章回覆於2010-10-07 11:34
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
7樓
回應

jack
捐贈 VP 給 怎有人這麼喜歡改暱稱 檢舉此回應
第一篇就叫你 try 了∼
[本篇文章回覆於2010-09-29 11:49]

拖到現在....
本篇文章回覆於2010-10-08 12:22
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
8樓
作者回應

小麥
檢舉此回應
也不是我不try啦

其實是我那時候看不懂@@"

也不知道要加在哪裡XD

真是抱歉><
本篇文章回覆於2010-10-08 17:02
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.