Hacker News
C++26: A User-Friednly assert() macro
MontagFTB
|next
[-]
maccard
|root
|parent
|next
[-]
bool is_even(int* valPtr) {
assert(valPtr != nullptr);
return *valPtr % 2;
}
Does not do what you think it does with nullptr. A major game engine [0] has a toggle to enable asserts in shipping builds, mostly for this reason[0] https://dev.epicgames.com/documentation/en-us/unreal-engine/...
samiv
|root
|parent
|next
|previous
[-]
usrnm
|root
|parent
|next
|previous
[-]
nyc_pizzadev
|root
|parent
|next
|previous
[-]
https://github.com/fiberfs/fiberfs/blob/7e79eaabbb180b0f1a79...
omoikane
|root
|parent
[-]
Abseil has the convention where instead of assert(), users call "CHECK" for checks that are guaranteed to happen at run time, or "DCHECK" for checks that will be compiled away when NDEBUG is defined.
https://github.com/abseil/abseil-cpp/blob/0093ac6cac892086a6...
https://github.com/abseil/abseil-cpp/blob/0093ac6cac892086a6...
jmalicki
|root
|parent
|next
|previous
[-]
`assert(vector.size() < 3)` is ridiculous to you?
omoikane
|next
|previous
[-]
There are a few things like that, for example:
https://en.cppreference.com/w/c/numeric/math/isnan - isnan is an implementation defined macro.
https://en.cppreference.com/w/c/io/fgetc - `getc` may be implemented as a macro, but often it's a function.
nealabq
|root
|parent
[-]
htons(..) and related socket-utility names are also often macros, but I'm pretty sure there is not a std::htons(..) in the C++ standard, partly because 'htons' is not an attractive name. Since it's (sometimes) a macro don't qualify its namespace like ::htons(..).
A long time ago in the Microsoft C (and later C++) dev envs there were macros named "min" and "max", which I thought were terrible names for macros.
nyc_pizzadev
|next
|previous
[-]
https://github.com/fiberfs/fiberfs/blob/7e79eaabbb180b0f1a79...
In this case, the ability to see the actual values that triggered the assert is way more helpful.