This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [lambda] Segmentation fault in simple lambda program


On 08/03/2009 09:39 PM, John Freeman wrote:
* Instead of transforming:
*
* [&] { i = 1; j = 2; k = 3; };
*
* into
*
* [&i,&j,&k] { i = 1; j = 2; k = 3; };
*
* and thus storing three pointers to int, transform it into:
*
* [sp=enclosing-stack-pointer] { var-from-stack(i,sp) = 1;
* var-from-stack(j,sp) = 2;
* var-from-stack(k,sp) = 3; };
*
* and only store one pointer.

This is preferred for reference default captures, but I was not familiar with stack pointer mechanics in GCC. I just wanted to get something working first that could be improved later.

Have a look at the documentation at the beginning of tree-nested.c. Having something so magic as an "enclosing stack pointer" got us into a lot of trouble in the past. It's much better to be explicit about things and create a struct to pop onto the stack of the caller.

Lets say you have

  int i, j, k, l;
  ...
  [&] { return i + j + k; }
  ...
  [&] { return j + k + l; }

you'd create a

  struct frame
  {
    int i,j,k,l;
  };

  frame f;
  [&f] { return f.i + f.j + f.k; }
  [&f] { return f.j + f.k + f.l; }

which is effectively what tree-nested.c does.


r~



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]