object.opEquals return type
Edward Diener
eddielee_no_spam_here at tropicsoft.com
Sun Feb 24 09:02:31 PST 2008
Janice Caron wrote:
> On 24/02/2008, Lars Ivar Igesund <larsivar at igesund.net> wrote:
>> Walter belive that an int is more efficient.
>
> The way I see it, the problem is that bool has a defined width. It
> shouldn't have, because bool is special.
>
> One possible solution would be to have explicit types bool8 and
> bool32, with "bool" meaning "either bool8 or bool32, at the compiler's
> discretion".
>
> The compiler would only need very simple rules to choose which to use
> (e.g. if function parameter or function return or local variable, use
> bool32, else use bool8), and allow either to implicitly and losslessly
> cast to the other.
>
> I think that would work. It would allow the programmer's intent to be
> specified in the code, but preserve efficiency at all levels.
Having more than one bool type complicates the situation for no good
reason. A bool is conceptually a 'true' or 'false' value, so it hardly
needs two types to handle that simple idea. I know you are saying that
having two types would enable the compiler to choose the most efficient,
but a compiler should be able to do this internally anyway without
creating the complication.
If the reason given by Walter for having OpEquals retur an 'int' instead
of a 'bool' is efficiency, than a 'bool' should internally be an 'int',
else that same reason can be given for any operation potentially
involving only a true or false value. Otherwise a 'bool' should
internally remain a 'byte' and efficiency should be much less of a
consideration than correct conceptual design.
Hopefully Walter will realize his delusion and correct his mistake.
More information about the Digitalmars-d
mailing list