www.digitalmars.com         C & C++   DMDScript  

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

Consider the following example

void throw_bad_alloc(Size si)
    // Do some throwing stuff
#define throw_bad_alloc(_si)        ((void)0)


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

    if(pv == NULL)

    return pv;

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


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

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

  inline void throw_bad_alloc(Size /*si*/)

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).

Jun 11 2003