Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Constants vs Locals
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00269906
Message ID:
00270358
Vues:
23
>Is there any reason to use a #DEFINEd constant instead of a local var? I've seen it done, but am not aware if the rationale, particularly when trying to debug...

I use #defines a lot, for example...

Living in Italy I have to code almost everything in English and Italian. I have a huge header file with an #IFDEF IN_ITALIAN ... #ELSE ... #ENDIF. It is awful but so far it's the best I found in terms of performance.

Often developing a new routine I have to dimension an array: well, at least one of the dimensions will be in a define. Chances are that I will need something more, or less, as development goes on. If the array is to be used in several places the #define goes in a header file, otherwise it goes at the top of the routine (and is easily visible with the debugger). I don't see a reason to waste a variable for static values. And one other reason, it's the closest we can go in VFP to strong typed variables declarations. As I've seen in other places in this thread, when we define PI as 3.14... there are absolutly no doubts about the data type we are using. I love the way VFP allows for "untyped" variables, but I would also love to have the possibility to "strong" type them. It would have saved me a few bad hours over the years.

But the main thing is that I shouldn't need to know the value of a constant. The name should be clear enough to understand it's meaning, otherwise it's easy to have an editor with a copy of the header file opened.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform