Member function increases size of a struct defined in a function - is this a bug?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 7 18:58:54 UTC 2020


On Fri, Feb 07, 2020 at 12:50:11PM +0000, Max Samukha via Digitalmars-d wrote:
> On Friday, 7 February 2020 at 12:36:23 UTC, Ferdinand Majerech wrote:
> > 
> > Is this the result of some D feature?
> > I can imagine this could happen if InnerFun had a silently added
> > context pointer, but I don't know of such a feature in D.
> > 
> 
> A pointer to the environment is a added to InnerFun for some reason
> (probably, a bug).

It's not a bug; the struct is declared inside function scope, and so
member functions can access function local variables. Therefore a
context pointer is necessary.


> You can work around by marking InnerFun 'static':
[...]

Yes, this disables access to function local variables from inside the
struct, so it eliminates the context pointer.


T

-- 
To provoke is to call someone stupid; to argue is to call each other stupid.


More information about the Digitalmars-d mailing list