Types soup with enum and bool
Maxim Fomin
maxim at maxim-fomin.ru
Tue Oct 29 11:37:54 PDT 2013
On Tuesday, 29 October 2013 at 18:23:03 UTC, bearophile wrote:
> Ali Çehreli:
>
>> >> enum Foo { A, B, C }
>> >> void main() {
>> >> bool[5] bools;
>> >> auto b = bools[2] != Foo.C;
>> >> bools[2] = Foo.A;
>> >> }
>>...
>> There was a long discussion about that. Walter was happy that
>> bool was a integer type. Many of us had objections:
>
> My problem is mostly with enums. I don't remember Walter
> explaining the rationale of the D enum conversion design. I
> prefer the C++11 enums.
>
> Bye,
> bearophile
Bools being integer types is reason of your problem with enums.
Relevant lines from your code are translated to:
bool b = 0 != 2;
bools[2] = 0;
taking into account that 'bool' is integer type having capacity
to represent values 0 and 1.
More information about the Digitalmars-d-learn
mailing list