I suggest you ...

C99: bool assignment error

//lint -A(C99)
typedef unsigned char uint8;
typedef _Bool bool;

const uint8 a = 100;
const uint8 b = 200;
int main(void)
{
bool test;
test = (a==b);
}
Report error 1564 or 921 (cast from int to bool)

Lint should know that the assignment of
test = (a==b) is save on C99.
Additionally, in our case it could not be deactivated by -estring(921,"cast from int to bool")

11 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    C. Breuer shared this idea  ·   ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Michael Metivier commented  · 

        In general, the "int vs. bool" is one of the largest sources of concern and confusion among our developers, who really want to know why something like "return (bool)(rv != 0);" is a required cast. We used to have an option to allow relationals to be treated as _Bool, but my understanding is that it only worked in conjunction with MISRA processing and has been removed from the newest iteration of the tool. I heartily support some way of handling this that doesn't involve a host of what appears to be superfluous casts all over the place.

      Feedback and Knowledge Base