hello,

I have 2 source files and want to use a constant value defined in the other source:

code is:




1. in the "header" file:

externdef pRegKeys:ptr byte
externdef NUMREGKEYSEARCHES:abs

2. in the "exporting" file:

pRegKeys label ptr byte
dd CStr("InProcServer32")
.....
dd CStr("RTFClassName")
NUMREGKEYSEARCHES equ ($ - pRegKeys) / sizeof dword

3. in the "importing" file (more or less irrelevant):

.while (ebx < NUMREGKEYSEARCHES)



But when assembling "export" file I get error:
optdlg.asm(43) : error A2005: symbol redefinition : NUMREGKEYSEARCHES

if I change the line temporarily to
NUMREGKEYSEARCHES equ 1

all assembles ok. What is wrong?

japheth
Posted on 2001-07-26 09:54:17 by japheth
It has to do with when the expression is evaluated. EQU is a text macro - you are assigning a string to a variable. Use '=' to solve your problem because the value is numeric. Another solution would be to proceed the expression with a '%' - which will force the evaluation of that expression when it's encounted. Another solution would be to export all the dependant values - which in this case is not possible - '$' needs to be evaluated where it is at.

Expert? No, I read the manual. :alright: (...many times!)
Posted on 2001-07-26 11:03:29 by bitRAKE
I use some text strings a lot so I defined some equ's.For example



PRGNAME equ "My Prog v1.2"
PRGDATE equ "2-2-01"
PRBUILD equ "ABC" ;this is the problem

abouttxt db "Program:",9,PROGNAME,13,10
db "Date:",9,PRGDATE,13,10
db "Build:",9,PRBUILD,0


If I use equ directive for strings which have less than five chars masm says that "initializer magnitude too large for specified size" Is there a any solution for this ?
Thanks
Posted on 2001-07-26 13:08:07 by LaptoniC
Use TEXTEQU instead of EQU. MASM tries to guess at what you want to do when you use EQU, but if you use TEXTEQU for strings and '=' for numbers, you will have less problems. Plus don't forget that you can force assemble-time evaluation of string macros with the '%'.
Posted on 2001-07-26 13:29:54 by bitRAKE
Ok,Thanks.
I got problems how to use this macro now I have learned.Thanks a lot.Here is working code :)



PRGNAME textequ <"My Prog v1.2">
PRGDATE textequ <"2-2-01">
PRBUILD textequ <"ABC">

abouttxt db "Program:",9,PRGNAME,13,10
db "Date:",9,PRGDATE,13,10
db "Build:",9,PRBUILD,0


I have finally found that it needs " in expression.
PRGNAME textequ <My Prog v1.2> does not works
It took my 20 minutes :)

:stupid:
Posted on 2001-07-26 14:57:28 by LaptoniC
Can I help you with a copy of Chapter 9 of the MASM manual? It's in English, but you seem to know the language well enough.

----
A man found a cocoon of the emperor moth and took it home to watch it emerge. One day a small opening appeared, and for several hours the moth struggled but couldn't seem to force its body past a certain point.

Deciding something was wrong, the man took scissors and snipped the remaining bit of cocoon. The moth emerged easily, its body large and swollen, the wings small and shriveled.

He expected that in a few hours the wings would spread out in their natural beauty, but they did not. Instead of developing into a creature free to fly, the moth spent its life dragging around a swollen body and shriveled wings.

The constricting cocoon and the struggle necessary to pass through the tiny opening are God's way of forcing fluid from the body into the wings. The "merciful" snip was, in reality, cruel. Sometimes the struggle is exactly what we need.

-- Leadership, from "Quote" magazine
Posted on 2001-07-26 15:43:43 by bitRAKE
:alright: I really appreciate you. Ohh btw thanks for the wings :grin: :grin: :grin: :grin: I really love this board :)
Posted on 2001-07-26 16:07:57 by LaptoniC
I must apologize because I have not supplied all information needed to analyze the problem. So the "simple" question turned out to be an "impossible" question. By now I have got it. Problem was the used macro CStr(), which was defined:



CStr macro y
local sym
.const
ifidni <y>,<"">
sym db 0
else
sym db y,0
endif
.code
exitm <offset sym>
endm


The array of string pointers I had defined originally was located in the code section and everything worked ok. But yesterday I had changed location of this array to the data section in another source file. And now the macro CStr had the unwanted side effect of changing the section and masm was right when telling me not to be able to calculate NUMREGKEYSEARCHES.

I have changed the macro to:



CStr macro y
local sym
CONST segment dword public 'DATA'
ifidni <y>,<"">
sym db 0
else
sym db y,0
endif
CONST ends
exitm <offset sym>
endm


so the actual section remains unchanged. Thanks to all who have posted.
Posted on 2001-07-27 02:20:25 by japheth
So what I said above is not a solution at all because the files are assembled separately and the EQU is evalutated correctly. Seems I got lost in the details at the end of your first post? Nice to see you found a solution though.
Posted on 2001-07-27 08:26:10 by bitRAKE
This is related to the above, but it's in a MACRO. Have to test this when I get home to see if this is fixed in 6.15? Just found this in the MASM Release Notes for 6.14:
Span-Dependent Equates in Macros and EXTERNDEF ABS
--------------------------------------------------
The ABS operator causes an identifier to be exported as a relocatable
unsized constant (see Programmer's Guide page 220). If ABS is used
with EXTERNDEF within a macro, and the constant being exported
depends on the difference between two addresses, the constant may not
be exported correctly. In some cases, the listing file will show the
correct value, but the value in the resulting .obj will be incorrect.
For instance, the following code will not evaluate correctly:

EXTERNDEF TableSize:ABS ; Will not be exported correctly

MAKETABLE MACRO
Table1 LABEL BYTE
DB 0, 1, 2
TableSize EQU $-Table1
ENDM

SEG1 SEGMENT
MAKETABLE
SEG1 ENDS

To avoid this problem, either use the 'PUBLIC' directive in place of
'EXTERNDEF', or put a label before the equate, within the macro.
Posted on 2001-07-27 10:50:16 by bitRAKE