digitalmars.D.bugs - Bad use of assert in sample winsamp.d
- Stewart Gordon (13/13) Nov 15 2004 The code of winsamp.d includes this line:
The code of winsamp.d includes this line:
assert(RegisterClassA(&wc));
Although at the moment it seems that the assert body is evaluated
whether -release is specified or not, this will not be the case in
general. As said, and quite sensibly, "The compiler may optionally not
evaluate assert expressions at all." When the compiler is improved so
that assert expressions aren't evaluated in release mode, the class
won't be registered at all, and so the program will not work.
The statement should therefore be replaced by
if (!RegisterClassA(&wc)) assert(false);
or perhaps better
if (!RegisterClassA(&wc)) throw new Error("RegisterClass failed!");
Stewart.
Nov 15 2004








Stewart Gordon <smjg_1998 yahoo.com>