Liste des Groupes | Revenir à cl c |
"I think truncation does not happen" is here logically equivalent to
the specific condition that ch is in the range 0 to UCHAR_MAX.
>
That can be asserted:
>
assert (0 <= ch && ch <= UCHAR_MAX);
>
If ch has the type unsigned char, then this condition is always
true.
>
We can think about a warning like that "controlling expression of
assert unconditionally true due to range of types", but it serves no
purpose. There is nothing wrong with asserting something that is
always true.
>
When assertions are enabled, the compiler can use their predicates
to reason about the code and not warn about conditions that are
precluded by assertions being true.
>
You will find that this already happens in today's compilers,
and not due to assert being treated specially. The assertion
translates into something like
>
if (!(0 <= ch && ch <= UCHAR_MAX)) do {
__assert_fail("0 <= ch && ch <= UCHAR_MAX", "foo.c", 42);
} while (0)
>
where __assert_fail is annotated a function which does not return.
Les messages affichés proviennent d'usenet.