www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 955] New: Passing arguments into functions - in, out, inout, const, and contracts

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=955

           Summary: Passing arguments into functions - in, out, inout,
                    const, and contracts
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jason.james.house gmail.com


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.


-- 
Feb 12 2007
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=955





------- Comment #1 from wbaxter gmail.com  2007-02-12 22:01 -------
Fixed size arrays are also Type 2, passed by reference.

   int func(int[2] xy) { xy[0] = 1; }  // modifies caller's xy[0]


-- 
Feb 12 2007