Better assert macro?

Create issue
Issue #7 resolved
David Williams created an issue

There are a number of problems with the standard C++ assert() macro. The one that gets me the most is that it's always present in debug builds and never present in release builds... this appears to be one of the reasons why debug builds are significantly slower. It might be useful to have a new assert macro which is controlled by some kind of 'Use Asserts' settings from CMake.

It also stops at the wrong place in Visual Studio (inside the standard library where assert is implmented, rather than at the line which caused the assert). There are various tips in books and articles about building a better assert.

Comments (8)

  1. David Williams reporter

    I've done a little research and this may not be necessary. Firstly there is a hack you can use to add messages to assert(): http://stackoverflow.com/a/3692961/849083

    Secondly it seems that the presence of the standard assert() macro can be controlled by NDEBUG, (which is seperate from whether it is a debug build or not).

  2. David Williams reporter

    It also occurs that a custom assert macro would mean that users can enable/disable asserts in PolyVox without affecting asserts in their own code. This could be particularly important as PolyVox is mostly headers.

  3. David Williams reporter

    We now have a macro called POLYVOX_ASSERT, and it is being used by the Vector class. Other code still needs to be modified to use it.

  4. Log in to comment