Connecting Tech Pros Worldwide Help | Site Map

New operator -- construction a side-effect?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 06:00 PM
DaKoadMunky
Guest
 
Posts: n/a
Default New operator -- construction a side-effect?

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.

  #2  
Old July 22nd, 2005, 06:01 PM
Ron Natalie
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.