3 ms·
That's a great list, thanks a lot. For the first case and third cases, as far as I know casting to void is the offical, supported, language-proper way to say "
by unwind 5y ago
That's a great list, thanks a lot.
For the first case and third cases, as far as I know casting to void is the offical, supported, language-proper way to say "this value is not being used" so no compiler improvement should break that.
The draft C18 standard says:
If a function call is evaluated as an expression statement for its side effects only, the discarding of its value can
be made explicit by converting the expression to a void expression by means of a cast
and (in 6.3.2.2 Void):
If an expression of any other type is evaluated as a void expression, its value or designator is
discarded. (A void expression is evaluated for its side effects.)
So that sounds like the proper solution, at least for those problems.
Regarding the alignment, I haven't seen that warning I think. This SO answer [1] recommends casting via void *, but that might count as an "obfuscation"; I would count it as just that, a "I'm know what I'm doing"-statement. :)
[1] https://stackoverflow.com/questions/33218873/how-to-properly-resolve-increase-in-pointer-alignment-with-clang https://stackoverflow.com/questions/33218873/how-to-properly...