[Implemented] Defined (Label, #PB_Label)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

[Implemented] Defined (Label, #PB_Label)

Post by Josh »

maybe it would be possible, to add labels to the defined-function. then i could do this:

Code: Select all

CompilerIf Defined(IID_NULL, #PB_Label) = #False
  IID_NULL: ; {00000000-0000-0000-0000-000000000000}
    Data.l $00000000
    Data.w $0000, $0000
    Data.b $00, $00, $00, $00, $00, $00, $00, $00
CompilerEndIf
ok, its not importent, i can make also with a constant, but it would be nice
sorry for my bad english
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Defined (Label, #PB_Label)

Post by Demivec »

Josh wrote:maybe it would be possible, to add labels to the defined-function. then i could do this:

Code: Select all

CompilerIf Defined(IID_NULL, #PB_Label) = #False
  IID_NULL: ; {00000000-0000-0000-0000-000000000000}
    Data.l $00000000
    Data.w $0000, $0000
    Data.b $00, $00, $00, $00, $00, $00, $00, $00
CompilerEndIf
ok, its not importent, i can make also with a constant, but it would be nice
I had the same idea at one time until I realized that labels are the only "constant" type that can be used before it's defined.

That would mean that the compiler function would have to determine if the label had been used in the code in any way up to that point, whether or not it had been defined yet.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Defined (Label, #PB_Label)

Post by Josh »

hmmmm. when i'm using the code (from my first posting) two times, one of the labels must be the first, which the compiler see. so he knows at the second time, that this label is definied.

at the moment i'm using this:

Code: Select all

CompilerIf Defined(IID_NULL, #PB_Constant) = #False : #IID_NULL = 0
  IID_NULL: ; {00000000-0000-0000-0000-000000000000}
    Data.l $00000000
    Data.w $0000, $0000
    Data.b $00, $00, $00, $00, $00, $00, $00, $00
CompilerEndIf
sorry for my bad english :?
sorry for my bad english
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Defined (Label, #PB_Label)

Post by Mistrel »

As a workaround you can define a constant that matches your label and check against that.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Defined (Label, #PB_Label)

Post by Josh »

Mistrel wrote:As a workaround you can define a constant that matches your label and check against that.
you mean like in my second posting?

the best would be, if Defined(....) makes the same like constants. if it is two times the same, the compiler do nothing. if there are two different contents, the compiler message an error. i know, thats a little bit tricky, because there is no fixed length for the data section, but maybe it could be used the data between the label and the next label for comparsion.
sorry for my bad english
Post Reply