Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
#DEFINE - Why?
Message
From
30/03/2008 19:58:17
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
30/03/2008 19:48:52
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01306848
Message ID:
01306849
Views:
11
>What is the simplest explanation as to why these are needed? Why not just set regular variable values? So what if they are constant and don't change?

One reason is that a variable needs additional overhead.
x = 5

* or:

#define SOMENUMBER 5
x = SOMENUMBER
are both equivalent; in this case, the number is first assigned directly.
local lnSomeNumber
lnSomeNumber = 5
...
x = lnSomeNumber
In this second example, not only does the variable lnSomeNumber need extra space (a slot in the variable table, I think, although I am not quite clear about all the technical details), but every time it is accessed, the variable must be looked up.

Other languages work different in this respect; so there is not so much difference between "constants" and "variables", but for safety, a variable may be declared as unchangable.

By the way, that should be another reason to use constants. A variable can be assigned any value at any moment. A constant is supposed to be treated as constant. Oh well, you could re - #DEFINE in another part of the program. Sigh.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform