← Back to context

Comment by throwaway2037

4 days ago

Unless you are doing trivial boolean comparisons, I always prefer a custom assert function that will also print a useful error message. Just telling me "Assertion failed: index < container.size()" isn't very helpful. What were the values compared?

Instead, my custom asset function (in C) looks like this:

    > void AssertWF(bool assertResult, char *format, ...)

Example:

    > AssertF(index < container.size(), "index:%d < container.size():%d", index, container.size());

If the first parameter is false, a detailed error message is printed:

    > fputs("Assert failed: ", stderr);
    > vfwprintf(stderr, format, ...);
    > abort();