andalso on preprocessor

General FreeBASIC programming questions.
Post Reply
Mysoft
Posts: 836
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

andalso on preprocessor

Post by Mysoft »

Code: Select all

#if defined(MyInt) andalso MyInt > 10
  #print "woooo"
#endif
i came across a .h that did that and apparently it was valid on C... but on freebasic andalso on preprocessor does not act as the shor circuited version...
  • FBIDETEMP.bas(1) error 20: Type mismatch in '#if defined(MyInt) andalso MyInt > 10'
thats a bug right?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: andalso on preprocessor

Post by MrSwiss »

Seems to me, that C's preprocessor is more lenient than FB's, on type checking.
BTW: neither And nor AndAlso work, but below does:

Code: Select all

#if defined(MyInt)

#If MyInt > 10
  #print "woooo"
#EndIf  ' MyInt > 10

#EndIf  ' defined(MyInt)
By contrast comparing two "of the same kind" works flawlessly:

Code: Select all

#If Defined(__FB_WIN32__) OrElse Defined(__FB_DOS__)
    #Define LF  ( Chr(13, 10) )
#Else
    #Define LF  ( Chr(10) )
#EndIf
Mysoft
Posts: 836
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Re: andalso on preprocessor

Post by Mysoft »

yeah indeed... because the "andalso/orelse" on preprocessor is doing the same as "and/or" i.e. its not shortcicuiting the parsing... the same difference from

Code: Select all

dim as integer ptr pBad = 0
if pBad andalso *pBad = 32 then print "ok" 'this would work fine
if pBad and *pBad = 32 then print "ok" 'this will crash as expected because it wont stop after the first condition fails
but so on the preprocessor... the andalso is not ignoring the if as soon the first one fails, without even trying to parse the rest

(i obviously already did the workaround of using nested #if's to fix the problem, but so was just posting for bugfix purposes) ^^
Post Reply