www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5807] New: Disallow mixed C/D style array declarations

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

           Summary: Disallow mixed C/D style array declarations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2011-04-03 10:33:53 PDT ---
An idea originally from simendsjo, then expanded.

The documentation about Postfix Array Declarations says:

 Rationale: The postfix form matches the way arrays are declared
 in C and C++, and supporting this form provides an easy migration
 path for programmers used to it.<
C style array declarations are handy (despite they add a little of extra complexity and confusion to the D language). But currently (DMD 2.052) D also supports a syntax like: // array of 5 dynamic arrays of ints. int[][5] c; int[] c[5]; int c[5][]; What's the purpose of such mixed syntax? 1) It's not present in C programs; 2) It's not used in normal native D programs; 3) And in my opinion it's not good to use even during the migration from C to D style, because it looks confusing (the order of ranges is inverted between C and D syntax). So I suggest to statically disallow such mixed syntax. ------------------ Currently the mixed syntax is not just useless and potentially confusing for the programmer, it also causes problems with some vector operations: void main() { int[] a1 = [1, 2, 3]; int[] a2 = new int[3]; a2[] = a1[]; // OK int[3] a3[] = a2[]; // line 5, Error } test.d(5): Error: cannot implicitly convert expression (a2[]) of type int[] to int[3u][] In theory if mixed C/D array declarations become disallowed, then there is only one meaning for the operation at line 5. (This is not very nice, but I don't see better solutions for this syntax problem with array operations). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 03 2011