It is currently Sun Mar 29, 2020 4:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Defined(Foo, #PB_Macro) ?
PostPosted: Wed May 11, 2011 12:10 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3792
Location: Berlin, Germany
Hi all,

I wanted to check, whether a macro is defined:
Code:
CompilerIf Defined(Foo, #PB_Macro)
   Debug "Macro 'Foo' is already defined."
CompilerEndIf

But this does not work (tesed with PB 4.51 and PB 4.60 Beta 3).
Why is there no cnstant #PB_Macro for this purpose?
Is there any other possibility to check, whether a particular macro is defined?

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Defined(Foo, #PB_Macro) ?
PostPosted: Wed May 11, 2011 8:47 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1257
Location: Germany, Glienicke
You can not test in this way because the macro (the name) will replace already during the test.
Code:
Macro Foo
 Debug 1
EndMacro

CompilerIf Defined(Foo, #PB_Macro)

CompilerEndIf


will be:
Code:
Macro Foo
 Debug 1
EndMacro

CompilerIf Defined(Debug 1, #PB_Macro)
;[...]

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Defined(Foo, #PB_Macro) ?
PostPosted: Wed May 11, 2011 8:48 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14009
Location: France
That's it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Defined(Foo, #PB_Macro) ?
PostPosted: Wed May 11, 2011 3:38 pm 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3792
Location: Berlin, Germany
Hi, thank you for the explanation!

Maybe it is possible (and desirable) to change the compiler a little, so that it makes and exception in this case:
If a macro name is an argument of Defined(), then the compiler will not expand the macro.

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Defined(Foo, #PB_Macro) ?
PostPosted: Wed May 11, 2011 8:13 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5796
Location: Germany
You can use a separate constant to guard against the double definition of a macro. Its not perfect, but it does the job for me:
Code:
CompilerIf Defined(macro_test_defined, #PB_Constant) = 0
  #macro_test_defined = 1
 
  Macro test()
    ; something
  EndMacro
CompilerEndIf

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject: Re: Defined(Foo, #PB_Macro) ?
PostPosted: Thu May 12, 2011 5:40 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3792
Location: Berlin, Germany
That's a good idea, thank you!

Regards, Little John

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye