The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bEaST2k on November 28, 2005, 05:20:35 PM

Title: Argument names in procedure
Post by: bEaST2k on November 28, 2005, 05:20:35 PM
Hi there,

just arrived at the masm forum and a hello @all  :U.

Maybe some of the masm-gurus here can answer this question:
Why masm-compiler is complaining about variable redefinition in this case:


[pseudo]
PROTO Foo DWORD

.data
szWord db "Hello masm",0

.code
start:
      invoke Foo,addr szWord
end start

Foo proc szWord:DWORD
     ; ....
Foo enp


Is there any way to bypass this (without renaming the szWord variable nor the szWord:DWORD parameter  :wink)?

Regard,
Fabian
Title: Re: Argument names in procedure
Post by: Vortex on November 28, 2005, 06:27:59 PM
Hi Fabian,

Welcome to the forum.

To assemble properly your code, you must to rename one of those szWord statements to avoid symbol redefinition and conflicting parameter definition.

Title: Re: Argument names in procedure
Post by: P1 on November 28, 2005, 06:46:12 PM
bEaST2k ,

Welcome to MASMforum!       :U

Read around the different areas and get a feel for the place.         :dance:

Read the help files and tutorials of MASM32.   It's best, if you download the most recent MASM32 package and install it. 

'Search' & Google are your friends for programming.  Then ask your questions.     

Technically, it's a pointer.  Foo proc pszWord:DWORD  Foo on you !   :green2

Regards,  P1   :8)
Title: Re: Argument names in procedure
Post by: Grincheux on November 28, 2005, 06:47:26 PM
I suggest :

Foo PROC lpszWord:LPSTR
     ; ....
Foo enp

Because the parameter is a pointer not a string.
Title: Re: Argument names in procedure
Post by: Vortex on November 28, 2005, 07:19:58 PM
Grincheux, LPSTR is defined as DWORD in windows.inc :

LPSTR typedef DWORD
Title: Re: Argument names in procedure
Post by: Grincheux on November 28, 2005, 07:26:48 PM
YES but it is easier to understand.
Title: Re: Argument names in procedure
Post by: Vortex on November 28, 2005, 07:35:56 PM
Quote from: Grincheux on November 28, 2005, 07:26:48 PM
YES but it is easier to understand.

Grincheux, one of the most powerfull features of asm is that you assume that all those LPSTR and similar statements are equal to DWORD This approach eliminates the need to remember various C based variable types during coding as there is no type casting in asm. In most of the cases, pointers are DWORD values.
Title: Re: Argument names in procedure
Post by: Grincheux on November 29, 2005, 03:57:01 AM
and characters are numbers...
Title: Re: Argument names in procedure
Post by: gabor on November 29, 2005, 09:53:45 AM
...and really talented ASM coders are aliens.  :green
Title: Re: Argument names in procedure
Post by: hutch-- on November 29, 2005, 10:07:11 AM
Administration is tolerant of Martians as we may have a few but we may draw the line on anyone from Venus unless they cool down a bit.
Title: Re: Argument names in procedure
Post by: BogdanOntanu on November 29, 2005, 06:40:45 PM
Ooops,
Indeed I am an alien on Earth... how did you found out?
But I look humman, I do all things like hummans do, I even die like hummans do...

Only because  I do programm huge applications in 32bits ASM... <--- did THAT simple fact blow my cover?

Now you only have to be carefull with GLOBAL variable names (same as in any programming language)

However multiple procedures can use the same name for variables, arguments or labels.
For example in TASM style:

My_Proc1 PROC
ARG: @@wnd_handle:dword, @@x1:dword,@@y1:dword
LOCAL @@tmp_x1:dword

... some code ...
@@loop_on_x:
...some code...
inc [@@x1]
dec ecx
jnz @@loop_on_x

ret
ENDP

My_Proc2 PROC
ARG @@parent_handle:dword, @@wnd_handle:dword, @@x1:dword
LOCAL @@tmp_x1:dword

...

@@loop_on_x:
    ...some code...
inc [@@x1]
dec ecx
jnz @@loop_on_x
ret
ENDP


Argument names will not colide inside PROCEDURES because they are SCOPED LOCAL to each procedure
Neither will LABELS not LOCAL variables...

So --> watch your GLOBALS :)
Title: Late, later, ... me
Post by: bEaST2k on December 12, 2005, 02:00:17 PM
Sorry for the late reply, you've better don't ask for the reason  :red...


Quote from: BogdanOntanu on November 29, 2005, 06:40:45 PM

My_Proc1 PROC
ARG: @@wnd_handle:dword, @@x1:dword,@@y1:dword
LOCAL @@tmp_x1:dword

My_Proc2 PROC
ARG @@parent_handle:dword, @@wnd_handle:dword, @@x1:dword
LOCAL @@tmp_x1:dword



Argument names will not colide inside PROCEDURES because they are SCOPED LOCAL to each procedure
Neither will LABELS not LOCAL variables...

So --> watch your GLOBALS :)



This  @@-Stuff came to my mind last week too. But come on, it's everything else then nice code  :wink!
But anyway, it's apparently the only way to get out of the redefinition...

Thanks for all the answers and especially for the warm reception  :U!