if Condition expression can't have function?
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 25 05:02:37 PDT 2014
On Fri, 25 Apr 2014 07:52:42 -0400, Nick Treleaven
<ntrel-public at yahoo.co.uk> wrote:
> On 25/04/2014 08:29, Matthias Walter via Digitalmars-d wrote:
>>> size_t find(T[] Array,T Element)
>>> > {
>> find returns a size_t being a nonnegativ number.
>>
>>> > return -1;
>> But here it returns -1.
>
> For size_t and uint 'dmd -w' seems to allow returning literal -1, but
> with ubyte I get:
> Error: cannot implicitly convert expression (-1) of type int to ubyte
>
> Is this inconsistent or is there a reason for this?
It is inconsistent, but it's well known legacy based on C rules.
See Integer promotion and arithmetic conversions here:
http://dlang.org/type
"Integer values cannot be implicitly converted to another type that cannot
represent the integer bit pattern after integral promotion."
-Steve
More information about the Digitalmars-d
mailing list