Author Topic: Non-mixing of types bool and integer  (Read 53 times)


  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Non-mixing of types bool and integer
« on: December 10, 2018, 01:30:16 AM »
    I think, it's better to exclude mixing of types bool and int. I mean, following code must give type cast warning:

        int a = true;

    true and false must be defined exactly as 0x01 and 0x00, but assigning without typecast is not good idea. Sometimes, it gives errors. Sometimes, i assign bool to integer or conversely erroneously, and compiler says nothing about it.

        int a = 5;
        bool b = a; /* What happens? Is it 5 or is it 1? */

    Bool logic and integer arithmetic usually don't not intersect. It's better to make these types non auto-convertible.
« Last Edit: December 12, 2018, 08:48:30 AM by acbaile »


  • Full Member
  • ***
  • Posts: 218
    • View Profile
Re: Non-mixing of types bool and integer
« Reply #1 on: December 10, 2018, 11:51:51 AM »
This is one of the core pillars of C flexibility. How many times have you been helped / hindered by this?