flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Bug (or strange behaviour) with sub macros

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Jul 2007, 01:21
Code:
macro test param
{
  macro sub_test param
  \{
    display param+'0'
  \}
  sub_test ; Works always
  sub_test 5 ; Fails if test didn't recieve a paramenter
}

macro test2 param
{
  display "OK, no problem without a param", 13, 10
}

test2  ; Works
test 1 ; Works, displays "05"
test   ; Fails at second sub_test line    


By some strange reason sub_test can't recieve a parameter if test macro didn't recieve one. This only happens when the name of the test formal parameter is the same in sub_test, otherwise this works.
Post 16 Jul 2007, 01:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 Jul 2007, 07:42
of course, because name of sub_test parameter is param, and that is also name of test's parameter.

before "test" is being preprocessed, all occurences of "param" in it's body are replaced by it's value. In your case, line "macro sub_test param" becomes "macro sub_test", and after that it is preprocessed.
Post 16 Jul 2007, 07:42
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Jul 2007, 14:46
Quote:

before "test" is being preprocessed, all occurences of "param" in it's body are replaced by it's value

I don't believe that. That means that in some moment "macro sub_test param" becomes "macro sub_test 1" because as you said param gets replaced, however the example prints "05", not "00" nor "01" nor error because using 1 as symbol when you can't.

[edit]Ahp, you CAN use a number as formal param Confused The code below works always. Sorry for the misunderstood
Code:
macro test param
{ 
  macro sub_test 1
  \{ 
    display 1+'0'
  \} 
  sub_test ; Works always 
  sub_test 5 ; Works always
} 

macro test2 param 
{ 
  display "OK, no problem without a param", 13, 10 
} 

test2  ; Works 
test  ; Works, displays "05"
    
[/edit]
Post 16 Jul 2007, 14:46
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 Jul 2007, 21:37
no problem, i hope problem is solved now Wink
Post 16 Jul 2007, 21:37
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.