By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

New operator -- construction a side-effect?

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"DaKoadMunky" <da*********@aol.com> wrote in message news:20040818074424.04158.00003071@mb-
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.
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.