Mail Archives: cygwin/1997/09/12/05:08:43
Colin Peters wrote:
>
> My beef with all this is: why does GCC do it this way at all? What purpose
> does the @NN serve? After all, GCC knows how to generate the correct
> function call given a prototype, it *generates* the @NN, so it doesn't
> need it to know what to do.
I see some benefit in this naming convention. Sometimes it happens that the
compiler generates the wrong code (and as a result the wrong symbol name)
of a function. This happens when the function prototype contains parameters
which are less than 4 bytes in size. For example, if you used a function
extern int _stdcall foo(char c);
void bar()
{
...
foo('a');
...
}
the compiler would generate (in order to call the 'foo' routine) a statement
putting a single-byte character on the stack and a call statement for the
external function '_foo AT 1'. No problem, if the foo function had been compiled
by gcc. If it has been compiled with MSVC (and all Windows NT or Windows 95
DLLs have been compiled with some kind of MSVC) not only one single byte
parameter would be expected by the called function but a DWORD (MSVC does DWORD
alignment for parameters and gcc doesn't).
If the linkage would be successful the foo function would remove the wrong number
of bytes from the stack (remember: _stdcall convention) before it returns
which would result in an unpredictable behaviour of the program. This kind of
problem is hard to find out.
If you have ever used the RSXNT package you would probably know this problem, because
the EMX (or on Win32 RSX) port of gcc creates plain names (without the '@nn' suffix)
also for _stdcall functions, but it doesn't align parameters (in fact, this
costed me some nights of debugging).
In other words:
1) If there are any problems with wrong or missing prototypes for
_stdcall functions the linker would complain with an 'unresolved external'
message. You will never get a program with wrong function calls.
2) In order to get all Win32 API functions working there must not be any
function prototype containing parameters which are less than 4 bytes
in size, even if the parameters are actually WORD or CHAR or BYTE or
something else. Please check your windows header files if they
contain prototypes with WORD or CHAR parameters. Replace WORD
or CHAR parameters by DWORD parameters.
> I don't think any other compilers add on @NN
> to the names of WINAPI functions like this. Why doesn't GCC just use the
> plain function name and call it with PASCAL calling convention? Someone
> please enlighten me.
>
In fact, MSVC mangles _stdcall names in the same manner as Cygnus gcc does.
Gunther
--
Gunther Ebert
iXOS Anwendungs-Software GmbH
Angerstrasse 40-42
D-04177 Leipzig
Phone : +49 341 48503-0
Fax : +49 341 48503-99
E-mail: mailto:gunther DOT ebert AT ixos-leipzig DOT de
www : http://www.ixos-leipzig.de
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -