Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Const....?
#11
Constants arent variables, it's shorthand that's tossed when your program is compiled.

CONST left = 75
CONST right = 77

if inp(&h60) = left then '...


which you compile, it changes to this:
if inp(&h60) = 75 then '...

etc. They have their purpose.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#12
That's right toonski. I didn't choose my words well I guess -- that happens often these days. :-?

I was thinking in 'variables' just to make my point about using variables & CONST together, like...

CONT a = "HELLO"

Shorthand is a good way to think of CONST. Heh...I guess everything in source code is 'shorthand' until it's compiled Wink

- Dav
Reply
#13
I heard somewhere that it's a speed issue... CONSTs are faster or something like that.
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#14
yes, since CONST stuff is hardcoded bits while vars must be looked up from memory.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#15
wow thanks for the responses guys, I understand it now. Meg's C program snippet helps a lot, even if there isnt that much to understand :wink: Thanks!
Reply
#16
I'll just continue the thread... Wink

CONST: faster than DIM or any other declaration and in C++/C a constant is replaced by its value by the preprocessor (AFAIK this is also done in QB).

CONST: can be used in an include file, a sequence of DIM SHARED's and Var = value's can't be used in an include file.

CONST: can be used throughout your whole project, DIM SHARED only works in the current module.

Some extra info Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)