Compilerfehler discards qualifiers


  • Mod

    ich habe gerade keinen standard zur hand aber ich glaube, es ist nicht definiert, dass char(true) == 1, lediglich dass char(true) != 0.

    Das ist selbstverständlich definiert.

    §4.7/4 schrieb:

    If the source type is bool, the value false is converted to zero and the value true is converted to one.



  • okay, mein fehler, sorry.


  • Mod

    Übrigens: Man sollte das tatsächlich so definieren können:

    bool XOR(bool lhs, bool rhs)
    {
        return char(lhs) ^ rhs; // Edit: Cast eingebaut. Promotion macht den Rest.
    }
    

    Egal welche Repräsentierung integrale Typen haben, gleiche Werte führen zu gleichen Bits, unterschiedliche Werte zu unterschiedlichen Bits. Wahrscheinlich muss man aber noch einen Cast nach char einbauen.



  • siehe auch

    4.5 Integral promotions
    6 A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one.

    5.12 Bitwise exclusive OR operator [expr.xor]
    exclusive-or-expression:
    and-expression
    exclusive-or-expression ˆ and-expression
    1 The usual arithmetic conversions are performed; the result is the bitwise exclusive OR function of the operands. The operator applies only to integral or unscoped enumeration operands.



  • Was soll das inline da? Und überhaupt, warum ein Template?

    Und so ein Satz von dir ... der doch fuer alles erstmal gleich die Template-/Macro-Maschine anwirft ...


Anmelden zum Antworten