955 – Passing arguments into functions - in, out, inout, const, and contracts

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 955 - Passing arguments into functions - in, out, inout, const, and contracts
Summary: Passing arguments into functions - in, out, inout, const, and contracts
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: No Owner
URL: http://www.digitalmars.com/d/1.0/func...
Keywords: spec
Depends on:
Blocks: 3106
Show dependency tree / graph
Reported: 2007年02月12日 21:41 UTC by Jason House
Modified: 2014年02月15日 13:12 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jason House 2007年02月12日 21:41:11 UTC
The description of in/out/inout/lazy leaves much to be desired. There's a thread on the mailing list titled "Passing arguments into functions - in, out, inout, const, and contracts" that has a number of people attempting to give more complete descriptions.
It seems like parameters fall into two categories
Type 1: fundamental types, structs, fixed size arrays
Type 2: variable size arrays, objects
in:
 Type 1 - Passed by value. changes to object have no external effect
 Type 2 - Passed by reference. function can't change the reference but can change the object
out:
 Type 1 - Passed by reference, initialized by default initializer
 Type 2 - Passed by reference, initialized by default initializer
inout:
 Type 1 - Passed by reference, can change the reference(?)
 Type 2 - Passed by reference, can change the reference
To me, the clarification of "in" parameters need clarification. For type 2, I'd expect the equivalant of a C++ "const T&" but that isn't the case and should really be spelled out.
Comment 1 Bill Baxter 2007年02月12日 22:01:19 UTC
Fixed size arrays are also Type 2, passed by reference.
 int func(int[2] xy) { xy[0] = 1; } // modifies caller's xy[0]
Comment 2 github-bugzilla 2012年01月21日 17:17:28 UTC
Commit pushed to https://github.com/D-Programming-Language/d-programming-language.org
https://github.com/D-Programming-Language/d-programming-language.org/commit/59e9decffc8f6fd3439492c406279ddf327b9b1b
fix Issue 955 - Passing arguments into functions - in, out, inout, const, and contracts


AltStyle によって変換されたページ (->オリジナル) /