News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

static in C

Started by n00b!, June 17, 2008, 01:29:20 PM

Previous topic - Next topic

n00b!

Hi, I want to convert the following C Code to MASM.
Do I have to declare the variable as a global one, or can I do it on another way?

void test() {
  static int i;
  i += 2;
}

jj2007

Depends on whether you need a global or local variable...

.data?
varI    dd ?  ; varI will be zero at progstart

.data
varI    dd 123  ; varI will be 123 at progstart

MyProc
LOCAL varI:DWORD
mov varI, 0   ; varI will be undefined whenever you enter this proc, so you better put a value  :wink

zooba

Yes, it will need to be global.

MASM doesn't have the same scoping rules as C, so you may want to include the name of the function in the variable name to make clear where it belongs.

Cheers,

Zooba :U

Tedd

The closest you can get is..

test proc
    .data
        i   DWORD 0
    .code
    add DWORD PTR [i],2
    ret
test endp


So I'd just go for a 'global' - with a slightly more meaningful name than 'i' :wink
No snowflake in an avalanche feels responsible.

GregL

You could also use the GLOBAL macro.


test PROC

    GLOBAL i DWORD 0
   
    add i, 2
    ret
test ENDP