Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does QB handle constants?
#1
Just wondering...are they simply variables that QB makes sure you don't touch, or are they just symbolic, and all occurences are replaced at compile time (like C's #define)?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#2
They are symbolic.
Reply
#3
Good. Memory-resident constants are slower.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#4
I think more importantly, in such a memory-starved language as QB, memory-resident constants would take up memory Wink
Reply
#5
That too. :wink:
That's especially true with RPGs and such - Operation Pong uses a hundred constants, just to keep track of player frames and directions, and tiles.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#6
Well, they're useful anyway. I wonder - if constants are just swapped, would it be an advantage to have a routine that runs just before a program is compiled that got swapped all the constants with their values and removed the CONST lines? So, like the way that QBMCX gets metas out and passes switches to the compiler, this program would strip consts out and put the prog in a temp file and get the compiler to compile that. Would that save a few bytes of memory?
Reply
#7
Not worth the trouble, IMHO - the only memory that would be saved is at compile-time. You don't usually have to care about that - only runtime should be a worry. If constants were just protected variables, then you'd have reason to tear your hair out. :wink:
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#8
Oh well, if anyone needs some more mem at compile time they'll know how to do it...
Reply
#9
How come:
CONST nana=90
a=a+nana

is faster then:
a=a+90


Because it is, place it in a loop and see for yourself.

Anyone?
Reply
#10
It's interesting to note, string constants are memory-resident and loaded into the variables and what-not at load-time, not compile-time. It's only numeric constants that are changed at compile-time.
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)