2

I'm trying to learn assembly language, using Netwide Assembler.

In tutorials, I see that there's an @n at the end of every function name, like:

CALL _GetStdHandle@4

CALL _WriteFile@20

CALL _ExitProcess@4

What does this @n mean?

(It seems to be part of the function name, in that I get error LNK2001: unresolved external symbol errors if I modify or remove that part, but obviously it's not part of the name of the C or C++ function that it was generated from. Where does it come from?)

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Rishabh
  • 35
  • 7

1 Answers1

7

Those are stdcall name decorations:

Name-decoration convention
An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12

A C/C++ compiler would handle this automatically for you (and so would some assemblers), which is why you haven't seen this before.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • As 4(int) + 8(double)=12?? Okay thanks for the Answer, it helps me!! – Rishabh Jan 20 '15 at 07:30
  • Right. It's just the sum of the sizes of all the arguments. – Michael Jan 20 '15 at 07:55
  • 3
    You should note that "stdcall" is a different calling convention than "cdecl". "stdcall" functions will remove arguments from the stack by using the "ret N" instruction while "cdecl" functions will use the "ret" instruction which will not remove arguments from the stack. Calling a "cdecl" function with the wrong number of arguments is not critical; calling a "stdcall" function is! Therefore the number of arguments is coded into the function name of "stdcall" functions to avoid such a case. – Martin Rosenau Jan 20 '15 at 10:56