繁体   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