On 3/8/07, Duncan Sands <[EMAIL PROTECTED]> wrote:
> in tree.def, in DEFTREECODE for call_expr, it says operand 2 is the
> static chain argument, or NULL. Can someone tell me or reference me to
> what static chain argument is?

It's for nested functions, eg

int parent (int n)
{
  int child (int m) { return m * n; }

  return child (2);
}

Notice how child using a variable of parent, namely
the parameter n.  This gets lowered to something like:

struct frame { int n; };

int child (struct frame *static_chain, int m) { return m * static_chain->n; }

int parent (int n)
{
  struct frame FRAME;
  FRAME.n = n;
  return child (&FRAME, 2);
}


Ah, nice, didn't know that was possible in C. Is that new in C99 or
it's a GCC extension?

Cheers,

Paulo Matos

Ciao,

Duncan.



--
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK

Reply via email to