Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constants and SYS(5) + SYS(2003)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00267724
Message ID:
00268660
Views:
36
>First, AFAIK no other language evaluates a compile time constant at run time. That in and of itself leads to some confusion. Once evaluated at compile time, it is what is says, a constant and cannot be changed. In this case the value can be changed, which, by definition, makes it a variable. Second, one of the benefits of using compile time constants is that the reference to it doesn't have to be evaluated at run time, leading to improved performance. That's not the case here. Anytime a native function call is used in assigning a compile time constant, it is re-revaluated at run time. It doesn't matter if the function always returns the same value (i.e. REPLICATE("A", 5)) or not (i.e. SYS(5) + SYS(2003)). It's re-evaluated.

Hi George,

I'm jumping back into the fray < g >. My this is confusing, isn't it. I did a little more reading last night on these constants and gained a little more understanding in how VFP uses them.

What happens at compile time is VFP just does a string replacement of the constants. No evaluation happens. If you #define SOME_CONSTANT 'MyExpression' the compiler just does a global search and replace of SOME_CONSTANT, then compiles the code. At run-time as VFP is executing the code SOME_CONSTANT doesn't exist, it has been replaced with 'MyExpression'. You can see this with following. Set logerrors on and compile the following:
#define TEST_CONSTANT 232'
x = TEST_CONSTANT + 1
You will get the following error:
x = 232' + 1
Error in line 2: Syntax error.
The constant has been replaced with it's value. If the constant was evaled at run-time the compiler would ignore the syntax error during compiling and the error would surface during program execution would it not?

Also in the hacker's guide is an example of how to defeat that behaviuor by bracketing the constant. Check it out, run the sample and pay attention to the c_tVERSION_BUILT constant. Its wrong, you think it will store the time when it was compiled, but it doesn't it returns the current time.

In light of that I don't think that constants will give you any performance gain simply because the evaluation happens at run-time, not at compiile time.

So what do you think? Am I understanding this correctly or am I still missing something.
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform