The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: RedXVII on October 16, 2005, 09:19:06 PM

Title: Underscores
Post by: RedXVII on October 16, 2005, 09:19:06 PM
Right, im learning assembly - however, ive only done limited C and C++ (which i regard as being rubbish).

My question:

Does the underscores in front of a variable change it in some way?

Thx  :U
Title: Re: Underscores
Post by: MusicalMike on October 17, 2005, 02:01:01 AM
If you have programmed in c before, you should know that the c/c++ compiler prefixes any global symbols with underscores durring compilation. In assembly language, the underscore is for the most part just another character.


varname                label        dword
_varname              label        dword
__varname            label        dword
___varname          label        dword


the above code demonstrates that all four of those names are unique. The above code sample works fine. Insidently, to get around ambiguity caused by say someone naming a global variable var1 (which would soon be prefixed with an underscore durring compile) and then declairing a local variable called _var1 (which you would expect to clash with the global) the visual c++ compiler seems to use name decoration to avoid conflicts.
Title: Re: Underscores
Post by: tenkey on October 17, 2005, 08:55:16 PM
The underscore (and all other name decorations) is not added during the middle of a compile. It is added only when the OBJ file is created. The name decoration is for the linker's benefit, not the compiler's. The linker requires unique names, and name decoration differentiates between overloaded functions. It also provides an indirect form of type checking when linking.

As MusicalMike says, the underscore is simply another character, and it's treated the same as a letter. It has no special meaning to the assembler, nor to the linker.
Title: Re: Underscores
Post by: RedXVII on October 21, 2005, 10:12:15 PM
Thanks  :U