Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original at vubiostat/r-yaml#22
Per Tim Hesterberg:
In C, the assert macro takes a boolean value, or something that can convert to a boolean value. At run time, if this value is true, nothing happens and the program continues. On false, an assertion is raised, the program crashes, and the line with the assert is printed out. So an assertion written:
assert(size > 0);
Would get something like this when the assertion is triggered:
Assertion failed: 'size > 0'
Probably with more information like file name, line number, etc. However, there is no second argument to assert to specify why the assert exists. To do that, a string literal can be inserted into the boolean argument like so:
assert(size > 0 && "need at least one element");
Assertion failed: 'size > 0 && "need at least one element"'
The string literal has the type of a character array. Arrays can decay to a pointer to the element type. Pointers can convert to boolean value, with non-null pointers becoming a true value. Arrays that decay to pointers always decay to non-null pointers. This means that string literals in a boolean context evaluate to true. By boolean logic, (X && true) == (X), so it is safe to append '&& "message"' to any boolean expression without changing its value.
If there is a code path that should never be reached, an assertion that always fails should be inserted. The smallest such form is:
assert(0);
Then, if a message is required:
assert(0 && "oops");
Both the arguments evaluate to false and the assertion always triggers. However, a common mistake with asserts is to omit the '0 &&' and write:
assert("oops");
With this mistake, "oops" always evaluated to true, the assertion never triggers, and this code branch is no longer protected. I think it's a good idea to pass on to the package maintainer so that future versions will not have this problem.