flat assembler
Message board for the users of flat assembler.

Index > Main > How do you know if a macro as being defined?

Author
Thread Post new topic Reply to topic
xanatose



Joined: 09 Jan 2004
Posts: 57
xanatose
I want to use some variables that are declared as public in one source and as extrn in another. And I want to use the same header for this.

In C I can do this

Code:
#ifdef __MyHeader_Internal__
  // public
  int g_myVariable;
#else
  // extern
  extern int g_myVariable;
#endif
    


But for this to work in fasm I need to know if a macro has being defined or not.
In the manual I found the keyword used can be used to know if a symbol is being used.
But I dont know how to know if a symbol as being declared or not.

Does someone know how to do this?
Post 29 Jun 2005, 03:17
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Post 29 Jun 2005, 04:28
View user's profile Send private message Visit poster's website Reply with quote
xanatose



Joined: 09 Jan 2004
Posts: 57
xanatose
Thank you,

So basically equ is declared in the preprocessor stage, while = is done at the assembler stage.

Thats why this did not work
[code]
MyHeader_Internal = 1

if defined MyHeader_Internal
; Private
else
;public
end if
[/b]

But this do
[code]
MyHeader_Internal equ 1

if defined MyHeader_Internal
; Private
else
; public
end if
[/b]

Two suggestions:
1. Include the FAQ inside the zip distribution.
2. Make the keywords bold in the pdf documentation so they could not be easily skipped. After some searching I did find defined in the manual (near the explanation for used with no examples.
Post 29 Jun 2005, 18:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
you got it wrong. First one DOES work, but i quess you didn't realize that "if" is handled at assembly time, so preprocessor code will be taken from both parts.
Code:
if 1
 a equ 1
 b = 1
else
 c equ 1
 d = 1
end if    

Here both "a" and "c" will be defined, because "equ"s (and all preprocessor stuff) is handled before handling "if". FASM's "if" is
something else than C's #if, C's one is preprocess-time, while in assembly it is handled later.
By the way, second code works in other manner than you thought,
with "MyHeader_Internal equ 1" code is preprocessed to
Code:
if defined 1
 ;Private
else
 ;public
end if
    

If it isn't defined then assembled code is
Code:
if defined MyHeader_Internal
  ;Private
else
  ;public
end if    

so it checks for constant named "MyHeader_Internal" (for example label), and suposing you haven't any label/constant of such name, condition is false.
Also [url=http://decard.net/?body=tajga&chapter=preproc my preprocessor tutorial[/url] might clear it for you.
Post 29 Jun 2005, 20:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.