open-watcom / open-watcom-v2

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

Error 'function modifier cannot be used on a variable' #1246

Open Baron-von-Riedesel opened 7 months ago

Baron-von-Riedesel commented 7 months ago

The error may be emitted by the C++ compiler wpp386 if your C++ code contains a std include file, i.e. math.h:

#include <math.h>

extern "C" void asmfunc(int, int );

int main ( int arcc, char * *argv )
{
    asmfunc(1, 2);
    return( 0 );
}

it happens only if the compiler option -ecc is given, though. This option is needed here to make the compiler add a preceding underscore to the external ( _asmfunc ).

jmalak commented 7 months ago

-ecc option change calling convention and part of this is name change in object file. If you want only change the symbol name you need not use -ecc option. You can use following construct to define real symbol for C/C++ symbol with prefixed underscore characters.

#pragma aux asmfunc "_*"
Baron-von-Riedesel commented 7 months ago

-ecc option change calling convention and part of this is name change in object file.

Are you sure about that? I've got the impression that options -3s/4s/5s or -3r/4r/5r actually determine the calling convention - while the -ecc option affects the name only.

The #pragma hack is ok, but still, the C++ compiler should not emit such strange error messages just because option -ecc is given. I noticed, however, that this bug report is more or less a double, there's already #1187

jmalak commented 7 months ago

Yes, the problem with the -ec... options for C++ compiler is known. But -ecc not only changes the name, but also changes the passing of parameters from the registers to the stack. -ecc is similar to -3s, but not the same. anyway, the -3r option passes the parameters through the registers. Combining -3r or -3s with any -ec.. option is inherently nonsense and can lead to unpredictable behavior. You should use either the -ec... or -3r or -3s option. Now -3r or -3s is for backwards compatibility because -ec... handles things correctly. Anyway by #pragma aux you can define default convention for parameter passing and naming etc. it can do same thing as -3r or -3s or any -ec.. option because internaly these options manipulate with default convention. generaly #pragma aux can handle any feature of calling convention but -ec.. or -3s or -3r are limited to specific cases.