![]() |
|
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) |
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
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)
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... 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 |