Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Why the define of ACE_NEW_RETURN use "while(0)"
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
风中飘絮  
View profile  
 More options Jul 20 2006, 4:51 am
Newsgroups: comp.soft-sys.ace
From: "风中飘絮" <wuye...@gmail.com>
Date: 20 Jul 2006 01:51:06 -0700
Local: Thurs, Jul 20 2006 4:51 am
Subject: Why the define of ACE_NEW_RETURN use "while(0)"
Hi,Everyone
    When I read the source code of ACE.
    I can't understand why the define of ACE_NEW_RETURN use "while(0)"?
    just in line 157 of the OS_Memory.h

00157 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00158    do { try { POINTER = new CONSTRUCTOR; } \
00159         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0;
return RET_VAL; } \
00160    } while (0)

Who will be kind enough to tell me that the defference between the
follow codes

00157 #    define ACE_NEW_RETURN(POINTER,CONSTRUCTOR,RET_VAL) \
00158    try { POINTER = new CONSTRUCTOR; } \
00159         catch (ACE_bad_alloc) { errno = ENOMEM; POINTER = 0;
return RET_VAL; } \
00160    

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas C. Schmidt  
View profile  
 More options Jul 20 2006, 7:43 am
Newsgroups: comp.soft-sys.ace
From: schm...@dre.vanderbilt.edu (Douglas C. Schmidt)
Date: Thu, 20 Jul 2006 06:43:48 -0500 (CDT)
Local: Thurs, Jul 20 2006 7:43 am
Subject: Re: [ace-users] Why the define of ACE_NEW_RETURN use "while(0)"
Hi,

>    When I read the source code of ACE.

To ensure that we have proper version/platform/compiler information,
please make sure you fill out the appropriate problem report form
(PRF), which is in

$ACE_ROOT/PROBLEM-REPORT-FORM
$TAO_ROOT/PROBLEM-REPORT-FORM

or in

$ACE_ROOT/BUG-REPORT-FORM
$TAO_ROOT/BUG-REPORT-FORM

in older versions of ACE+TAO.  Make sure to include this information
when asking any questions about ACE+TAO since otherwise we have to
"guess" what version/platform/compiler/options you've using, which is
error-prone and slows down our responsiveness.

I don't think there is a difference in this case - either the former
or the latter code could be used just fine.  If you'd like to enter a
bugzilla entry about this we'll clean it up at some point.

thanks,

     Doug
--
Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schm...@vanderbilt.edu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Näwe  
View profile  
 More options Jul 20 2006, 8:37 am
Newsgroups: comp.soft-sys.ace
From: Stefan Näwe <naew...@atlas.de>
Date: Thu, 20 Jul 2006 14:37:34 +0200
Local: Thurs, Jul 20 2006 8:37 am
Subject: Re: [ace-users] Why the define of ACE_NEW_RETURN use "while(0)"
Douglas C. Schmidt schrieb:

This forces you to add an ';':

ACE_NEW_RETURN(p, Foo, -1);

Which will make some editors (e.g. Emacs) happy.

Stefan
--
----------------------------------------------------------------------
Stefan Naewe                                     ATLAS Elektronik GmbH
                                                         Dept.: NUS T4
phone: +49-(0)421-457-1378                Sebaldsbruecker Heerstr. 235
fax:   +49-(0)421-457-3913                                28305 Bremen

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
J.T. Conklin  
View profile  
 More options Jul 20 2006, 9:26 am
Newsgroups: comp.soft-sys.ace
From: j...@acorntoolworks.com (J.T. Conklin)
Date: Thu, 20 Jul 2006 06:26:37 -0700
Local: Thurs, Jul 20 2006 9:26 am
Subject: Re: [ace-users] Why the define of ACE_NEW_RETURN use "while(0)"
Hi Dr. Schmidt,

schm...@dre.vanderbilt.edu (Douglas C. Schmidt) writes:

While in this particular case, the do-while(0) is unnecessary, it is
the general idiom we use to ensure "function-like" macros expand to a
single statement.  

IMO, It seems more desirable for us to use the idiom consistantly,
even in the cases where it's not strictly necessary, than it would be
to "clean up" those that don't need it.  Because if sometime down the
road someone adds another statement to one of these cases and forgets
to add the do-while(0) wrapper, it would be easy to introduce hard to
find bugs in our users code.

But if someone decides that this is important, I'd claim that it
should be done across the board instead of as each macro is encountered.
That's a pretty big task, not one to be taken up lightly.

    --jtc

--
J.T. Conklin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Douglas C. Schmidt  
View profile  
 More options Jul 20 2006, 10:35 am
Newsgroups: comp.soft-sys.ace
From: "Douglas C. Schmidt" <schm...@dre.vanderbilt.edu>
Date: Thu, 20 Jul 2006 09:35:13 -0500
Local: Thurs, Jul 20 2006 10:35 am
Subject: Re: [ace-users] Why the define of ACE_NEW_RETURN use "while(0)"

Hi J.T.,

BTW, I looked into this a bit more and we need the do/while(0) even for
the try/catch case.  Here's a small example that illustrates why:

----------------------------------------

int main ()
{
  if (10 > 20)
    try {
    }
    catch (...) {
    }; // Compile error if the ';' is here!
  else
    ;
  return 0;

}

----------------------------------------

Whereas this works fine:

----------------------------------------

int main ()
{
  if (10 > 20)
    do
      {
        try {
        }
        catch (...) {
        }
      } while (0); // It's fine to have the ';' here.
  else
    ;
  return 0;

}

----------------------------------------

> IMO, It seems more desirable for us to use the idiom consistantly,
> even in the cases where it's not strictly necessary, than it would be
> to "clean up" those that don't need it.  Because if sometime down the
> road someone adds another statement to one of these cases and forgets
> to add the do-while(0) wrapper, it would be easy to introduce hard to
> find bugs in our users code.

> But if someone decides that this is important, I'd claim that it
> should be done across the board instead of as each macro is encountered.
> That's a pretty big task, not one to be taken up lightly.

Right, and in this case it's essential!

Thanks,

        Doug


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »