open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
959 stars 157 forks source link

New-style function declaration with old style function definition causes weird errors #681

Open tkchia opened 3 years ago

tkchia commented 3 years ago

Under Open Watcom wcc 2.0 beta May 17 2020, if I compile the source file

long far pascal bar(int, int, int, long);
long far pascal (*p)(int, int, int, long);

long
foo(int x, int y, int z, long w)
{
    return bar(x, y, z, w);
}

long far pascal
bar(x, y, z, w)
    long w;
{
    return x + y + z + w;
}

void
baz()
{
    p = bar;
    p = &bar;
}

with the command

wcc -bt=dos -ms -oxs -fo test.c

I get these error messages:

Open Watcom C x86 16-bit Optimizing Compiler
Version 2.0 beta May 17 2020 00:24:48 (32-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.
test8.c(20): Error! E1010: Type mismatch
test8.c(20): Note! N2003: source conversion type is 'long (__far __pascal *)(int __p1,int __p2,int __p3,long __p4)'
test8.c(20): Note! N2004: target conversion type is 'long (__far __pascal *)(int __p1,int __p2,int __p3,long __p4)'
test8.c(21): Error! E1010: Type mismatch
test8.c(21): Note! N2003: source conversion type is 'long (__far *)(int __p1,int __p2,int __p3,long __p4)'
test8.c(21): Note! N2004: target conversion type is 'long (__far __pascal *)(int __p1,int __p2,int __p3,long __p4)'
test8.c: 22 lines, included 48, 0 warnings, 2 errors

The weirdness seems to be triggered at least when I take the address of a __far __pascal function which is declared with a new-style (C89) prototype, but is later defined in an old-style (K&R) way. There was some further weirdness (line 21) when I tried to refer to the address of bar (...) using &bar instead of just bar.

I came across this problem while trying to get VESA's VBE/AI SDK to build under Open Watcom.

Thank you!

jmalak commented 3 years ago

Thanks for reporting it. If you have two declarations (prototypes) then it is merged by rules that resulting prototype can contains modifiers from both prototypes. It could be source of problem in your situation. The mixing of ISO and K&R prototypes is not good practice and I didn't test such use of OW compilers anyway. OW can have some mistake to handle such code. I will fix it.

tkchia commented 3 years ago

Hello @jmalak,

Thank you for looking into this. I think it would be helpful if wcc could at least detect such cases and flag a warning (or error).

Thank you!

jmalak commented 3 years ago

I think it is OW bug in merging ISO and K&R prototypes because if I change bar function to be ISO definition then no problem.