www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - More (void) sadness ... a more compelling example this time

Consider the following example

#ifdef __SYNSOFT_DBS_OPNEW_THROWS_EXCEPTIONS
void throw_bad_alloc(Size si)
{
    // Do some throwing stuff
}
#else
#define throw_bad_alloc(_si)        ((void)0)
#endif /* __SYNSOFT_DBS_OPNEW_THROWS_EXCEPTIONS */

////////////////////////////////////////////////////////////////////////////
////


void *operator new(Size si)
{
    void *pv  =   Win_Alloc(si);

    if(pv == NULL)
    {
        throw_bad_alloc(si);
    }

    return pv;
}


When the compiler does not support throwing exceptions on mem exhaustion,
throw_bad_alloc() is a macro that translates to

  ((void)si);

in order to prevent the compiler from whitering about an unused argument.
However, by (void) casting it, we precipitate the otherwise grand -wc
warning.

Naturally an alternative is to write throw_bad_alloc() as an empty inline
function


  #else
  inline void throw_bad_alloc(Size /*si*/)
  {}
  #endif /* __SYNSOFT_DBS_OPNEW_THROWS_EXCEPTIONS */

which I am now doing (since I cannot wait), but in general this may not
always be easy or desirable (people tend to like to not have to change code
on big projects unless there are real bugs).


Matthew
Jun 11 2003