Poll: Unseen is crazy...
You do not have permission to vote in this poll.
Defo...no doubt...
100.00%
1 100.00%
Defo again - but he may actually be on to something here...
0%
0 0%
Total 1 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arbitrary CONST values
#21
(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.
Reply
#22
Steve, wouldn't that slow program execution a lot?
Reply
#23
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.
Reply
#24
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.
Reply
#25
DEF Pete CONST Pain in the ASCII

Now Steve would vote defo for that one!

Pete Big Grin Big Grin
Reply
#26
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
Reply
#27
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
Reply
#28
(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
Reply
#29
Thanks and +1 for the information being so in depth. Never knwe about the _TRUE _FALSE either so double thanks!

Unseen
Reply
#30
How 'bout this?
Code: (Select All)
False = 0
True = Not False
Print True, False
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Upcoming changes to CONST may affect your code SMcNeill 14 2,697 12-30-2023, 05:13 PM
Last Post: Kernelpanic
  TYPE and CONST within SUB/FUNCTION TerryRitchie 9 1,939 07-11-2023, 01:22 AM
Last Post: bplus
  suggestion: initialize array values within the DIM statement bobalooie 19 3,305 12-22-2022, 06:46 PM
Last Post: Kernelpanic
  Convert IPv4 dotted quad into four decimal values bert22306 6 1,522 10-31-2022, 03:30 AM
Last Post: bert22306
Bug Color CONST Warning v1.5+ bplus 3 796 05-05-2022, 06:13 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)