Error A2181: initializer must be a string or single item

Started by jj2007, February 02, 2011, 02:42:53 PM

Previous topic - Next topic

jj2007

This struct gives me A2181: initializer must be a string or single item:

MyStruct STRUCT
;MyDummy DWORD ?
MyRect RECT <?,?,?,?>
MyCenterX dd ?
MyCenterY dd ?
MyStart dd ?
MyStruct ENDS


I have tried {} as suggested by MSDN but no success. Strangely enough, it works fine with MyDummy activated.

Any ideas?
:eek

redskull

Perhaps it's a bug in your versin of ml; in version 9, is assembles fine either way.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dgkimpton

Assembles fine here... possibly the error is actually somewhere else in your code and this is where it is being reported?

Try putting it in a simple program on it's own...

try this
.586
.model flat, stdcall   
option casemap :none   

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data

MyStruct STRUCT
MyRect RECT <?,?,?,?>
MyCenterX dd ?
MyCenterY dd ?
MyStart dd ?
MyStruct ENDS

SomeString db "Hello", 0

.code

main:
invoke MessageBox, NULL, ADDR SomeString , ADDR SomeString , MB_OK

invoke ExitProcess, 0
end main


If this works then it is something else in your code...

dedndave

what you have seems like it ought to work
have you tried...
MyStruct STRUCT
MyRect RECT <>
MyCenterX dd ?
MyCenterY dd ?
MyStart dd ?
MyStruct ENDS

jj2007

I have tried loads of variants. The standalone proggie by dgkimpton did not have the bold part...

Quote.data
MyStruct STRUCT
; MyDummy   dd ?  ; DISABLE and see the error message.
MyRect RECT <?>
MyCenterX dd ?
MyCenterY dd ?
MyStart dd ?
MyStruct ENDS

MyS   MyStruct <?>

dgkimpton

To be fair nor did the OP.

I'm not sure you can do that... if you can it's new to me...

You can certainly use it in a procedure to declare local storage:

test proc
LOCAL MyS:MyStruct

         ; Do stuff with MyS

        ret
test endp

dgkimpton

Well hell, learn't something new :)

You can almost do what you want but it seems the syntax you wanted was:


MyStruct STRUCT
MyRect RECT <?>
MyCenterX dd ?
MyCenterY dd ?
MyStart dd ?
MyStruct ENDS

MyS  MyStruct <>


Then it works fine...

{edit}
I'll go out on a limb and suggest this is because you have marked every single field of your structure as uninitialised, so there is no need to mark the instance that way again.. after all what are you marking as uninitialised when ever member is already marked that way?

Thanks for making me look into this... it's bound to be very handy going forward :) A serious case of the blind man leading the blind ;)

{edit 2}
Some nice explanation here: http://www.hep.wisc.edu/~pinghc/asm5.html

MichaelW

Assuming the goal is to initialize the members, this works for me:

MyStruct STRUCT
    MyDummy  DWORD ?
    MyRect  RECT <>
    MyCenterX dd ?
    MyCenterY dd ?
    MyStart dd ?
MyStruct ENDS
    .data
        mys MyStruct <1,{2,3,4,5},6,7,8>
    .code

eschew obfuscation

jj2007

Quote from: dgkimpton on February 02, 2011, 07:19:33 PM
To be fair nor did the OP.

The OP posted only a structure, not a snippet claiming to be complete :bg

Quote from: dgkimpton on February 02, 2011, 07:30:15 PM
Well hell, learn't something new :)
MyS  MyStruct <>
...
I'll go out on a limb and suggest this is because you have marked every single field of your structure as uninitialised, so there is no need to mark the instance that way again..

You are the man, thanks :U