简体   繁体   中英

How can I enable C99 in OpenWatcom 1.9?

I have an old project targeting DOS (yes, really) which I need to update and re-compile. The project is using the Open Watcom 1.9 C / C++ compilers and the JWasm assembler. Under no circumstances I can use other compilers or assemblers, because that project contains a lot of code specific to them.

What works:

I can compile and link the project as is without any issues with the existing code. I can change code and can re-compile and link the project.

My problem:

While updating and improving the code, I would like to use a part of C99 syntax / extended syntax. Notably, I would like to use designators in array initializers like that:

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

I have read somewhere (can't remember where) that only gcc supports that syntax, but the Open Watcom 1.9 manuals state the opposite. From c_readme.pdf , chapter 6.5, page 46:

6.5 Differences from Open Watcom Version 1.3
Following is a list of changes made in Open Watcom C/C++ 1.4:
• Support for C99 designated initializers has been added to the C compiler, for example "struct {int a, b;} c = {.a=0, .b=1};". This is also supported for arrays, for example "int a[4] = {[0]=5, [3]=2};".

Please note that I really tried to provide an authoritative link to that document, but right now openwatcom.org is down (again), and I can't remember the exact location of the document on that website. However, the document is included in the installation archive of OpenWatcom 1.9, which you can still can download. For example, the Windows Version for C is here .

When I try to compile a source file which uses designators in array initializers as shown above, I am getting just a syntax error from the respective line. I have tried the POSIX compiler driver as well as the normal C compiler, but both produce the same syntax error. These are the command lines I used:

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

So what do I have to do to be able to use designators in array initializers with OpenWatcom C/C++ 1.9?

You can compile code with Open Watcom Compiler fork (see also option -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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM