[Issue 481] Letting compiler determine length for fixed-length arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 30 17:20:14 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=481


hsteoh at quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh at quickfur.ath.cx


--- Comment #12 from hsteoh at quickfur.ath.cx 2012-04-30 17:21:24 PDT ---
(In reply to comment #10)
[...]
> If some dude can't count the number of elements he puts in his 10 elements
> array initializer, he'd better stop programming at all. Introducing some
> strange Perl-like syntax for that is madness.

You're totally missing the point. Code like this is very prone to bugs:

int[5] x = [1,2,3,4,5];

because as soon as somebody edits the list of elements, the count will be
wrong. Restating something that the compiler already knows is a bad idea. (The
same problem occurs in C/C++; in the C case, depending on the compiler, you may
even get a gratuitous array overrun.)

The proposed int[$] = [ ... ]; is a very good solution, because $ already means
"length of array" in D, and would fit seamlessly into the existing language.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list