D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4553 - D2 Language Docs: http://www.digitalmars.com/d/2.0/struct.html
Summary: D2 Language Docs: http://www.digitalmars.com/d/2.0/struct.html
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-01 10:43 UTC by Andrej Mitrovic
Modified: 2012-01-15 14:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2010-08-01 10:43:56 UTC
"Static Initialization of Structs"

There is inconsistency between the examples.
Replace X with S in all the examples.
        
In the 4th example, this line:
S s = { 1, i };   // q.a = 1, q.b = i, q.c = 0, q.d = 7

Should be replaced with:        
S q = { 1, i };   // q.a = 1, q.b = i, q.c = 0, q.d = 7



"Const and Invariant Structs"

In the code example the statement t = s; is not compilable:

const struct S { int a; int b = 2; }

void main()
{
    S s = S(3);    // initializes s.a to 3
    S t;           // initializes t.a to 0
    t = s;         // ok, t.a is now 3
    //~ t.a = 4;   // error, t.a is const
}

test3.d(29): Error: variable test3.main.t cannot modify const



"Struct Constructors"

There are no code examples here. A simple one could be added:

struct S {
    int x;
    int y;
    
    this (int x_val, int y_val) {
        x = x_val;
        y = y_val;
    }
}

void main() {
    S s = S(4, 5);
}