Hi,

Is there any way to make MASM to reduce the scope of data labels declared withing a procedure but in data section(segment)
(An anology of static variables in C)
So the code below wouldn't cause symbol redefinition error?

PROC1
.data
temp dd
.code

ENDP


PROC2
.data
temp dd
.code

ENDP
Posted on 2003-01-28 12:48:47 by Sergo
It is possible using a custom EPILOGUE/PROLOGUE and another macro. Unfortunately, I don't have time to code it right now. :(

The syntax would result in something like:
testPROC PROC xyz:DWORD

STATIC varName:DWORD

testPROC ENDP
The STATIC macro would create a global label based on current PROC name and the varName provided - effectively making varName availible in all PROCs. The STATIC variables would be accessible globally, but only by specifying the full name.

Seems like much work for this feature, but it would be a nice feature to have!
Posted on 2003-01-28 14:58:02 by bitRAKE
If you want something avaiable in all PROCs, COMM variables will do the job.

PROC1
.data
COMM temp :DWORD
.code

ENDP


PROC2
.data
;temp dd dont need to redefine.
.code

ENDP

COMM variables are global variable. They are created at link time, so you cannot initilize them.

I'm not really sure what you are asking for:

Is there any way to make MASM to reduce the scope of data labels declared withing a procedure but in data section(segment)
(An anology of static variables in C)
So the code below wouldn't cause symbol redefinition error?

Reduce the scope? Dont make the variable PUBLIC? Be careful you will get hard to find bugs because ML will put the variable address at one place in one OBJ file and a different address in another OBJ file. As you program runs, the address of the variable will appear to suddenly change.

Maybe something like this would work:

PROC1
.data
temp label DWORD
dd 0
.code

ENDP


PROC2
.data
temp label DWORD
dd 0
.code

ENDP

or maybe...

PROC1
.data
temp:
dd 0
.code

ENDP


PROC2
.data
temp:
dd 0
.code

ENDP

I know "temp label DWORD" will treat the label like a variable, but wont allocate any space, heance the dd 0.
Posted on 2003-01-29 01:56:19 by ThoughtCriminal
Sergo,

A compiler just puts the static variable in the DATA section like a global variable so there is no difference, the only distinction is between LOCAL variables that are created on the stack and global variables that are set at assembly time.

You could mess around to emulate STATIC but its just as easy to allocate the variable as a GLOBAL in the data section and don't call it from anywhere else.

Regards,

hutch@movsd.com
Posted on 2003-01-29 04:33:58 by hutch--
unless you're going to resort to macro trickery, the easiest option is probably
source-module global (ie, not externally visible) variables with names like
"funcname_variablename". somebody could probably come up with a macro
to make this nicer.
Posted on 2003-01-29 06:20:36 by f0dder
All I want is an option so the data labes within procedure can be treated as code labels with OPTION SCOPED,
so I don't have reinvent label names or prepend finction names.
( LABEL trick doesn't work)

BTW, does anybody know the link to MASM refernce (not MS Programmer?s Guide or short reference) in old hlp format. I saw it on one site but forgot the address
Posted on 2003-01-30 22:25:44 by Sergo