flat assembler
Message board for the users of flat assembler.

Index > Main > Compiler bug with 'if defined/else'?

Author
Thread Post new topic Reply to topic
ejamesr



Joined: 04 Feb 2011
Posts: 52
Location: Provo, Utah, USA
ejamesr 04 Nov 2012, 03:17
In the following, TEST_2 is always defined even though it should not be. I've tested this in v1.70.03 and v1.71.05:
Code:
; With the if statement below, TEST_2 is always defined,
; whether the next line is commented out or not:
define TEST_1 1

if defined TEST_1
   display 'TEST_1 was defined',13,10
else
   ; this next define will always happen
   ; this is not correct...
   define TEST_2 1
   display 'TEST_2 was defined',13,10
end if

if defined TEST_2
   display 'TEST_2 is always defined',13,10
   display 'no matter the status',13,10
   display 'of TEST_1',13,10
end if

if ~ defined TEST_1
   display 'TEST_1 was not defined',13,10
else
   display 'TEST_1 was defined',13,10
end if   

    

Has anyone else noticed this? Is there a work around?

I'm trying to define some equates conditionally, based on other equates. If this is truly a bug and the behavior is 'fixed', a lot of existing code may break. So for now, I will have to list each equate separately and just comment out the ones I don't want; I haven't found another way for this to work.

Alternatively, I hope somebody can point me to the errors of my ways above -- thank you!

ejamesr
Post 04 Nov 2012, 03:17
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 04 Nov 2012, 03:40
The problem here is that you are mixing the preprocessor with the assembler. define and equ are preprocessor directives and are processed during the preprocessing pass before the if statements are evaluated by the assembler.

A method to solve this for you is to use the assembler equals (=) instead of define.
Code:
TEST_1 = 1
if defined TEST_1
;...    
Post 04 Nov 2012, 03:40
View user's profile Send private message Visit poster's website Reply with quote
ejamesr



Joined: 04 Feb 2011
Posts: 52
Location: Provo, Utah, USA
ejamesr 04 Nov 2012, 03:50
revolution,

Thank you -- that works perfectly (as long as BOTH symbols are defined with equals).
Post 04 Nov 2012, 03:50
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 04 Nov 2012, 04:24
ejamesr wrote:
Thank you -- that works perfectly (as long as BOTH symbols are defined with equals).
Yes. All variables will need to use the same method. The important thing is to understand the preprocessor/assembler paradigm.
Post 04 Nov 2012, 04:24
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.