Doc Comments /
Struct
Structs & Unions
More Information
align example
The ability to specify alignment is mentioned but the syntax for doing so is not given. As far as I can tell you prefix the struct or union with the alignment requirements using align(n). So to get a struct where all members are 1-byte aligned you would do:
![]() |
|
sizeof property for unions
.sizeof is undocumented for unions
Passing structures into and out of functions
Details on how structures are passed into and out of functions would be useful. Are they defaultly passed by value? Are they returned by value? There is a comment that suggests you should not use structs as properties because they are returned by reference. - BradBeveridge?
- As far as I know, they're always passed by value, no matter how big they are. -- BillBaxter
Why no constructors?
For POD-types constructors can make code much more readable, take for example a struct to represent a 3D vector:
![]() |
|
As I understand it, the main requirement is that structs and unions must be trivially copiable, so it would make sense that copy-constructors and copy-assignment-operators are disallowed, but constructors in general?
(corollary question: why is the assignment operator allowed for structs without this caveat?)
There is a limited constructor-type interface: See "static initialization of structs"
Message
Put your comments about the official/non-official page here.
Links
See the corresponding page in the D Specification: