1 matches bool, 2 matches long
MattCoder
mattcoder at hotmail.com
Tue Apr 30 14:35:11 PDT 2013
On Monday, 29 April 2013 at 18:39:27 UTC, Walter Bright wrote:
> On 4/29/2013 10:10 AM, Steven Schveighoffer wrote:
>> On Sat, 27 Apr 2013 13:27:39 -0700, Walter Bright
>> <newshound2 at digitalmars.com>
>> wrote:
>> .
>> . .
>> bool isn't an integer. It can implicitly cast to an integer,
>> but that's it.
>> Once we implement that rule, everything falls into place. If
>> you want to pass a
>> "true" boolean literal, use true. If you want to pass a
>> "false" boolean literal
>> use false. Using 1 and 0 may be convenient, and may also be
>> valid, but when it
>> matches an integral type as well as bool, then it's ambiguous.
>
> Carefully reading your statement, you are still arguing that
> matching 1 to long should be "better" than matching it to bool.
Walter, Don't you agree that the current way can be confusing?
For example, the following code generates 2 differents
results/output:
import std.stdio;
void foo(bool b) { writeln("bool"); }
void foo(long l) { writeln("long"); }
void main()
{
long num = 0;
foo(num);
foo(0);
foo(2);
}
output:
long
bool
long
Regardless the fact that num is a variable (long), the first 2
foo calls in my perspective means foo(0), and should generate the
same output. Don't you agree with that?
More information about the Digitalmars-d
mailing list