Static Array with negative index results in a strange error-message

Dgame r.schuett.1987 at gmail.com
Mon Apr 23 14:36:12 UTC 2018


On Monday, 23 April 2018 at 13:48:07 UTC, Steven Schveighoffer 
wrote:
> On 4/23/18 9:32 AM, Dgame wrote:
>> char[-1] c;
>> 
>> results in
>> 
>> Error: char[18446744073709551615LU] size 1 * 
>> 18446744073709551615 exceeds 0x7fffffff size limit for static 
>> array
>> 
>> Should we fix that? A negative index should be IMO detected 
>> sooner/with a cleaner error message.
>
> Hm.. at least it's detected. I actually don't think the message 
> is wrong: -1 is a valid size_t literal, and results in that 
> number.
>
> if you did:
>
> enum size_t x = -1;
> char[x] c;
>
> You would get the same result, and I don't know how we would 
> fix that.
>
> -Steve

C's error message is

error: 'c' declared as an array with a negative size
     char c[-1];

That is more understandable.


More information about the Digitalmars-d-learn mailing list