• Why the define of ACE_NEW_RETURN use "while(0)"

    From Andreas Leitgeb@21:1/5 to avishfc@gmail.com on Tue Oct 3 18:00:50 2017
    avishfc@gmail.com <avishfc@gmail.com> wrote:
    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)

    Hi can anyone help me to know
    does any memory get allocated in ACE_NEW_RETURN. If yes then where
    we are freeing it. Explain me why it is needed to allocate memory
    in ACE_NEW_RETURN.What is purpose of ACE_NEW_RETURN.

    Allocation of memory happens in "POINTER = new CONSTRUCTOR;" (where
    CONSTRUCTOR will be replaced by some actual class name and its con-
    struction arguments (possibly none) in parentheses (always needed)
    and POINTER will be replaced by an actual pointer variable. Both are
    provided as arguments to the macro, as well as an return-value to
    be returned from current function in case of allocation failure.

    Obviously, the memory is not immediately freed within the macro, but
    only "after use" somewhere else (and not even always at the same place
    where the macro was used).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avishfc@gmail.com@21:1/5 to All on Tue Oct 3 10:20:24 2017
    On Thursday, July 20, 2006 at 2:21:06 PM UTC+5:30, 风中飘絮 wrote:
    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

    Hi can anyone help me to know
    does any memory get allocated in ACE_NEW_RETURN. If yes then where we are freeing it. Explain me why it is needed to allocate memory in ACE_NEW_RETURN.What is purpose of ACE_NEW_RETURN.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)