QB64 Phoenix Edition
Arbitrary CONST values - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2)
+--- Thread: Arbitrary CONST values (/showthread.php?tid=4033)

Pages: 1 2 3 4


RE: Arbitrary CONST values - SMcNeill - 10-27-2025

(10-27-2025, 09:37 AM)a740g Wrote: While I generally agree that a constant should be know at compile-time, some languages do offer const-qualified objects where a variable becomes read-only after its initial assignment. I think that was the original ask - which is completely valid IMO. QB64 does not have anything like that ATM. But I think it may be a useful feature.

I would think a nice _LockVar could be nice.

DIM foo AS STRING
foo = "Compiled on: " + DATE$
_LockVar foo   'this now says that foo will never change in value, making it read-only.  It locks the value of the variable from changing.   I can now pass foo to other routines, without having to worry about it being corrupted accidently.

Could also add an _UnlockVar as complimentary usage.   It'd basically be similar to locking a file, but for use with a variable instead.


RE: Arbitrary CONST values - Jack - 10-27-2025

Steve, wouldn't that slow program execution a lot?


RE: Arbitrary CONST values - a740g - 10-27-2025

Not exactly. The compiler should enforce that no assignments occur after the initial one during compile time. That way, there will be no runtime cost.

We could simply use the CONST keyword instead of using a new one. If the CONST expression does not fold to a literal the compiler should treat it as a CONST-like object.


RE: Arbitrary CONST values - Kernelpanic - 10-27-2025

Since QB64 is supposed to be compatible with QuickBasic, one solution could be a (_)Const-lock to make it clear that it is a QB64 extension.


RE: Arbitrary CONST values - Pete - 10-28-2025

DEF Pete CONST Pain in the ASCII

Now Steve would vote defo for that one!

Pete Big Grin Big Grin


RE: Arbitrary CONST values - Unseen Machine - 10-28-2025

As some of you dont seem to think im totally gone...id suggest _RTCONST (as in) Run Time Constant - i,e it get defined at runtime not compile time!

Again, I still think im a few spanners short of a toolbox!

Unseen


RE: Arbitrary CONST values - Unseen Machine - 10-28-2025

I think also I may have found a small bug... 


To demonstrate : 
Code: (Select All)

CONST True = 1
CONST False = NOT True '// Therefore anything not 1 = FALSE

PRINT "My false is = 0 so as False is supposed to be anything thats not true lets see if 0 = False!"

FOR i% = 0 TO 15
  PRINT True, False '// Lets see if they stay the same
  IF 0 = False THEN PRINT "0 = false" ELSE PRINT "0 whilst not being = true is not actually false!"
NEXT

I noticed it a while back when using flags to control gl without using a SPECIFIC True Value. Just saying True = not false, my Gl loop would run when it shouldn't...is it a bug or expected behaviour....

John


RE: Arbitrary CONST values - ahenry3068 - 10-29-2025

(10-28-2025, 11:30 PM)Unseen Machine Wrote: I think also I may have found a small bug... 


To demonstrate : 
Code: (Select All)

CONST True = 1
CONST False = NOT True '// Therefore anything not 1 = FALSE

PRINT "My false is = 0 so as False is supposed to be anything thats not true lets see if 0 = False!"

FOR i% = 0 TO 15
  PRINT True, False '// Lets see if they stay the same
  IF 0 = False THEN PRINT "0 = false" ELSE PRINT "0 whilst not being = true is not actually false!"
NEXT

I noticed it a while back when using flags to control gl without using a SPECIFIC True Value. Just saying True = not false, my Gl loop would run when it shouldn't...is it a bug or expected behaviour....

John



    I understand your confusion but this is expected and how almost all BASIC's act.

NOT in BASIC is BITWISE not logical      


1 as an int is   &B0000000000000001


NOT 1 is &B1111111111111110


  This is a non zero value and acts as TRUE.


Only NOT -1 ends up being 0   So TRUE should be -1   



BTW: In QB64PE 4.2    _TRUE & _FALSE are already pre defined so just use those. 

Try this code.  

Code: (Select All)
FOR I = -2 to 3
        print _BIN$(NOT I)
NEXT



RE: Arbitrary CONST values - Unseen Machine - 10-29-2025

Thanks and +1 for the information being so in depth. Never knwe about the _TRUE _FALSE either so double thanks!

Unseen


RE: Arbitrary CONST values - bplus - 10-29-2025

How 'bout this?
Code: (Select All)
False = 0
True = Not False
Print True, False