New operator -- construction a side-effect?

D

DaKoadMunky

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.
 
R

Ron Natalie

DaKoadMunky said:
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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top