More function decorations II (pool_allocator, mt_allocator, debug, stl_list)

Richard Guenther rguenther@suse.de
Wed Apr 22 14:31:00 GMT 2009


On Wed, 22 Apr 2009, Gabriel Dos Reis wrote:

> Yes, but they also share this:
> 
>     struct Complex {
>        double re;
>        double im;
>     };
> 
>     Complex* newComplex() {
>        Complex* p = (Complex*) malloc(sizeof (Complex));
>        p->re = 0;
>        p-> im = 0;
>     }
> 
>     int main(void) {
>        Complex* p = newComplex();
>        *(double*)p = 9.0;     // #1
>         return p->im;
>     }
> 
> I don't think #1 ends the lifetime of  the object pointed to by
> `p' either.  The point here is that you have to factor in together
> all the various places that allow accessing an object value
> with different types other than the dynamic of effective types.
> (3.10/15 in particular).

I always find the "an aggregate or union type ..." clause confusing
as that suggests it is ok to access double x; via an lvalue of
type Complex while I am sure the opposite is meant - the lvalue
is of type of a member of the object type.

Richard.



More information about the Libstdc++ mailing list