Processing #Define

In C, we can use the preprocessor, especially #define, to create "dynamic" variables, if you will.

For example, if I set

int time = millis()

then the "time" equals the millis() of when it was set.

But with

#define TIME millis()

millis() is only substituted, not evaluated, therefore creating a "dynamic" variable.

Is there a way to do such a thing in Processing?

millis() is only substituted, not evaluated, therefore creating a "dynamic" variable.

The substitution occurs just before the compiler is invoked. There is no "dynamic" variable created.

The problem that you are trying to solve escapes me.

The problem that you are trying to solve escapes me.

pseduo code:

int a = millis()
...some code...
int b = millis()
...some more code...
int c = millis()

I can't declare a, b, and c all at the top because I want to know how long it is between a and b, and b and c.

But look at this:

#define VAR millis()
int a = VAR
...some code...
int b = VAR
...some more code...
int c = VAR

Now millis() is substituted into each instance of VAR, but it is not evaluated until the execution reaches that line in code. But there is not a preprocessor in Java.

From the point of view of the C compiler, there is absolutely no difference between the two blocks of code you showed, since the preprocessor changes the second block of code into the first block of code before the compiler even becomes aware of the code.

The values assigned to a, b, and c will not all be the same, if the intervening, but not shown code, takes some time to execute.

Sorry....

what I meant to say is that I can't do anything like the second one in processing.