c correction (was: cloning/invocation)
Jecel Assumpcao Jr
jecel at merlintec.com
Thu Aug 29 20:44:39 UTC 2002
I wrote:
> You have to properly initialize the stack frame. How do you do that?
> By copying some values from the code or some other area.
>
> int foo ( char c ) {
> int count = 0; max = 99;
>
> while ( count < max ) { .... }
> }
>
> Some initial code in "foo" must copy 0 and 99 to the right places on
> the stack.
Most people on this list probably aren't interested in the fine details
of C semantics, but after I sent the above it started to look strange
to me so I made a quick test and found I was wrong.
For dynamic variables, initializer expressions are just a short hand for
code to execute the implied assignment and the expression is *not*
evaluated at compile time. So
int gg = 12;
void foo() { int total = gg*2; ...... }
main() { foo(); gg = 45; foo(); ... }
will use the value of "gg" at the time foo is invoked, unlike what I had
stated. What I wrote is correct for static variables, so this is a case
of same syntax but two different semantics. I guess this makes sense in
practice as we could "#define gg 12" to get the effect of evaluating
the expression at compile time.
-- Jecel
More information about the Squeak-dev
mailing list
|