[Implemented] Allowing Logical Statments in Compiler If

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

[Implemented] Allowing Logical Statments in Compiler If

Post by Dreglor »

It would be great to allow the CompilerIf Statement to accept all of the logical statments; AND, OR, XOR, NOT
~Dreglor
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Re: Allowing Logical Statments in Compiler If

Post by horst »

Dreglor wrote:It would be great to allow the CompilerIf Statement to accept all of the logical statments; AND, OR, XOR, NOT
CompilerIf can only evaluate expressions with constants, where bit operators &|~! can be used.

AND, OR, XOR, NOT are designed to handle conditions with variables.
Horst.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Allowing Logical Statments in Compiler If

Post by Trond »

horst wrote:
Dreglor wrote:It would be great to allow the CompilerIf Statement to accept all of the logical statments; AND, OR, XOR, NOT
CompilerIf can only evaluate expressions with constants, where bit operators &|~! can be used.

AND, OR, XOR, NOT are designed to handle conditions with variables.
He knows that, but he wants to use the other operators with constants as well, which is why he posted in this forum.

You can emulate them using macros:

Code: Select all

Macro COr(A, B)
  ((((A)<>0)+((B)<>0))<>0)
EndMacro

Macro CAnd(A, B)
  ((((A)<>0)+((B)<>0))=2)
EndMacro

Macro CXor(A, B)
  ((((A)<>0)+((B)<>0))=1)
EndMacro

Macro CNot(A)
  ((A)<>0)
EndMacro

; #MAX_PATH = 1024 Or #MAX_PATH = 260
CompilerIf COr(#MAX_PATH = 1024, #MAX_PATH = 260)
  Debug 1
CompilerElse
  Debug 0
CompilerEndIf

; #MAX_PATH = 1024 And #MAX_PATH = 260
CompilerIf CAnd(#MAX_PATH = 1024, #MAX_PATH = 260)
  Debug 1
CompilerElse
  Debug 0
CompilerEndIf

; #ACK = 6 Or (#BEL = 6 And #SYN = 7)
CompilerIf COr(#ACK = 6, CAnd(#BEL = 6, #SYN = 7))

CompilerEndIf
Post Reply