Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#DEFINE - Why?
Message
De
30/03/2008 19:58:17
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
30/03/2008 19:48:52
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01306848
Message ID:
01306849
Vues:
12
>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform