www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Static Array with negative index results in a strange error-message

reply Dgame <r.schuett.1987 gmail.com> writes:
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.
Apr 23 2018
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Apr 23 2018
parent reply Dgame <r.schuett.1987 gmail.com> writes:
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.
Apr 23 2018
parent reply Dgame <r.schuett.1987 gmail.com> writes:
It's really fun playing around:

char[int.max - 1] c;

results in

Internal error: dmd/backend/cgcod.c 634

with DMD 2.079. Guess I or somebody else should report this.
Apr 23 2018
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 4/23/18 11:09 AM, Dgame wrote:
 It's really fun playing around:
 
 char[int.max - 1] c;
 
 results in
 
 Internal error: dmd/backend/cgcod.c 634
 
 with DMD 2.079. Guess I or somebody else should report this.
 
 
Yes, this is an ICE (Internal compiler error). Those should ALWAYS be reported. -Steve
Apr 23 2018