[Issue 4551] D2 Language Docs: http://www.digitalmars.com/d/2.0/arrays.html

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 5 15:43:31 PDT 2010


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


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #1 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-08-05 15:43:28 PDT ---
changeset http://www.dsource.org/projects/phobos/changeset/1810

Note, I left a few things unfixed that you pointed out:

(In reply to comment #0)
> "Usage"
> 
> In the code example, the lines:
> 
> p = s;        // p points to the first element of the array s.
> p = a;        // p points to the first element of the array a.
> 
> Give compiler errors:
> 
> Error: cannot implicitly convert expression (s) of
> type int[3u] to int*
> Error: cannot implicitly convert expression (a) of
> type int[] to int*
> 
> These should probably be replaced with:
> 
> p = &s[0];        // p points to the first element of the array s.
> p = &a[0];        // p points to the first element of the array a.

Don already fixed these

> "Functions as Array Properties"
> 
> The body of foo() in the example code is not defined and we get the usual
> linker nonsense. 
> Replace the example code with the following:
> 
> void foo(int[] a, int x) { };
> 
> void main() {
>     int[] array;
>     foo(array, 3);
>     array.foo(3);    // means the same thing
> }

The example isn't meant to be a complete program.  Prototypes without
implementation are allowed as long as you define the function later.  Yes,
there is no point in defining a D prototype since the function must be defined
in the module itself, but essentially, the implementation of foo isn't of
importance here, just the fact you can call it that way.

> "Static Initialization of Static Arrays"
> 
> The documentation states:
> "These arrays are static when they appear in global scope. Otherwise, they need
> to be marked with const or static storage classes to make them static arrays."
> 
> In non-global scope, I can only compile if the array is marked with static or
> static const.
> 
> const alone will not compile for me:
> 
> enum Color { red, blue, green };
> 
> void main() { 
>     const int value[Color.max + 1] = [ Color.blue:6, Color.green:2, Color.red:5
> ]; 
> }
> 
> test2.d(192): Error: Integer constant expression expected instead of Color.blue
> test2.d(192): Error: Integer constant expression expected instead of
> Color.green
> test2.d(192): Error: Integer constant expression expected instead of Color.red
> test2.d(192): Error: Integer constant expression expected instead of Color.blue
> test2.d(192): Error: Integer constant expression expected instead of
> Color.green
> test2.d(192): Error: Integer constant expression expected instead of Color.red

I'm not sure what was meant here by Walter.  I suspect that "Static array"
should be changed to "fixed sized array" everywhere, but that's a huge change,
that I'm not comfortable making.  I think the text is meant to say that in
order to make an array a "static variable" (i.e. keeps its value across
function calls) you have to apply the static attribute.

-- 
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