>Is there a reason that I shouldn't just do this in the first place?
It depends on your debugging needs. If the assertion is absolutely critical for the application to continue, and the information from a failed assert is sufficient, by all means use assert. On the other hand, if it's not a fatal error, you can usually log/trace and continue on. On the third hand, a lot of people replace the standard assert with their own macro that provides more helpful information.
Also remember that assert is meant to check code integrity. You're saying "This should always be true, and I'm writing code based on that assumption. If the assumption is false, the code is broken and this assert is there to keep the bug from making it to release". If the assertion fails, it's a logic bug that needs to be fixed.
I'd wager that instead of asserting that a and b will never be equal, you should be testing this as a case at runtime and producing a suitable diagnostic (ie. return value, setting errno, etc...). Otherwise, I'd immediately ask you how you know that a and b will never be equal. Are you generating those values? Do you have an explicit runtime check surrounding each call to this function?
Your example smells funny, and that makes your question suspect as well.
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004