Connecting Tech Pros Worldwide Forums | Help | Site Map

New operator -- construction a side-effect?

DaKoadMunky
Guest
 
Posts: n/a
#1: Jul 22 '05
Is it fair to say that in the statement

T* t = new T;

that construction of T is a side-effect and that it need occur only before the
next sequence point?

If that is the case, what about something like this...

T *t;
(t=new T)->SomeFunc();

It is my understanding that there is a sequence point prior to entering a
function and that all arguments to a function and its side-effects will have
been evaluated prior to entering a function. Does that include the implict
argument representing the "this" object?













It is my understanding that the new operator consists of memory allocation
using an appropriate operator new and memory initialization using an
appropriate constructor.

It is also my understanding that in the above statement that assignment to T* t
could occur either before or after the constructor for T executes.

Ron Natalie
Guest
 
Posts: n/a
#2: Jul 22 '05

re: New operator -- construction a side-effect?



"DaKoadMunky" <dakoadmunky@aol.com> wrote in message news:20040818074424.04158.00003071@mb-[color=blue]
> It is my understanding that there is a sequence point prior to entering a
> function and that all arguments to a function and its side-effects will have
> been evaluated prior to entering a function. Does that include the implict
> argument representing the "this" object?[/color]

To answer your initial question, yes it is safe. There is a function call inherent
in allocating the storage (operator new) and calling a constructor. The return from
these functions are a sequence point. The rules say that the object lifetime begins
at these points (depending on the type). Either way you're ok.

To answer the question above, yes, but you have encountered a sequence point
before SomeFunc() was called.
Closed Thread