簡體   English   中英

如何在 OpenWatcom 1.9 中啟用 C99?

[英]How can I enable C99 in OpenWatcom 1.9?

我有一個針對 DOS 的舊項目(是的,真的),我需要更新和重新編譯。 該項目使用 Open Watcom 1.9 C / C++ 編譯器和 JWasm 匯編器。 在任何情況下,我都不能使用其他編譯器或匯編器,因為該項目包含許多特定於它們的代碼。

什么有效:

我可以按原樣編譯和鏈接項目,而現有代碼沒有任何問題。 我可以更改代碼並重新編譯和鏈接項目。

我的問題:

在更新和改進代碼的同時,我想使用 C99 語法/擴展語法的一部分。 值得注意的是,我想在這樣的數組初始值設定項中使用指示符:

double foo[2] = {
  [0] = 1.5,
  [1] = 0.5
};

我在某處(不記得在哪里)讀到只有 gcc 支持該語法,但 Open Watcom 1.9 手冊 state 正好相反。 來自c_readme.pdf ,第 6.5 章,第 46 頁:

6.5 與 Open Watcom 版本 1.3 的區別
以下是 Open Watcom C/C++ 1.4 中所做的更改列表:
• C 編譯器添加了對 C99 指定初始化程序的支持,例如“struct {int a, b;} c = {.a=0, .b=1};”。 arrays 也支持這一點,例如“int a[4] = {[0]=5, [3]=2};”。

請注意,我確實試圖提供該文檔的權威鏈接,但現在 openwatcom.org 已關閉(再次),我不記得該文檔在該網站上的確切位置。 但是,該文檔包含在 OpenWatcom 1.9 的安裝存檔中,您仍然可以下載。 例如 C 的 Windows 版本在這里

當我嘗試編譯在數組初始值設定項中使用指示符的源文件時,如上所示,我只收到來自相應行的語法錯誤。 我已經嘗試過 POSIX 編譯器驅動程序以及普通的 C 編譯器,但兩者都會產生相同的語法錯誤。 這些是我使用的命令行:

owcc.exe -c -v -mtune=686 -g3f -Wstop-after-errors=20 -fmessage-full-path -fno-short-enum -fptune=586 -mcmodel=h -O0 -finline-math -Wextra -std=c99 -b DOS -fo=obj\Release\foo.obj foo.cpp

wpp.exe -6 -bt=DOS -d3 -e20 -ef -ei -er -fpi87 -fp5 -mh -od -wx -zdf -zff -zgf -zt256 -zu -fo=obj\Release\foo.obj foo.cpp

那么我必須做些什么才能在 OpenWatcom C/C++ 1.9 的數組初始值設定項中使用指示符?

您可以使用Open Watcom Compiler fork編譯代碼(另請參見選項-za99 ) -

#include <stdio.h>
int main() {
    double foo[2] = {[0] = 1.5, [1] = 0.5};
    printf("foo => {%f, %f}\n", foo[0], foo[1]);
    return 0;
}

Output -

Open Watcom C/C++ x86 32-bit Compile and Link Utility
Version 2.0 beta Dec 31 2020 01:11:17 (64-bit)
Copyright (c) 2002-2020 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
    wcc386 st.c
Open Watcom C x86 32-bit Optimizing Compiler
Version 2.0 beta Dec 31 2020 00:56:05 (64-bit)
Copyright (c) 2002-2020 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
st.c: 9 lines, included 799, 0 warnings, 0 errors
Code size: 89
    wlink @__wcl__.lnk
Open Watcom Linker Version 2.0 beta Dec 31 2020 00:49:52 (64-bit)
Copyright (c) 2002-2020 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
loading object files
searching libraries
creating a Windows NT character-mode executable

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM