[tree-ssa] Why are bools cast to int in conditionals?
Paul Koning
pkoning@equallogic.com
Thu Apr 22 15:31:00 GMT 2004
>>>>> "Joseph" == Joseph S Myers <jsm@polyomino.org.uk> writes:
Joseph> On Thu, 22 Apr 2004, Paul Koning wrote:
>> The trouble with that is that promotion to int is in fact
>> language-specific -- C/C++ may define things that way, but most
>> other high level languages don't. Not that modula-3 or pascal is
>> a high visibility front-end, but I don't think that viewing this
>> issue as language-INdependent is right.
Joseph> Other languages convert bool to int yielding values other
Joseph> than 0 (false) and 1 (true), or otherwise promote them such
Joseph> that a comparison of promoted / converted values can't be
Joseph> narrowed to one of narrower types? The fact that there's an
Joseph> implicit promotion may be language-dependent - each front end
Joseph> should build trees reflecting what the language's rules are -
Joseph> but the question is whether the transformation narrowing an
Joseph> operation on promoted types is also language-dependent.
I sure don't understand this. In most languages (Pascal, Algol, etc.)
Boolean is a first-class type, and the notion of implicit conversion
to int simply does not exist.
Do you mean that the compiler can invent such an implicit conversion
as a way to transform the input into a language-independent form?
That may be true, and the C rule may be a fine way to do that.
But that isn't the same as saying that there's an implicit conversion
notion in the language. Otherwise bool == int would be a legal
operation in every language -- and that is not the case.
paul
More information about the Gcc
mailing list