www.digitalmars.com         C & C++   DMDScript  

D - reference modifiers

reply imr1984 <imr1984_member pathlink.com> writes:
why does D have the reference modifiers in, out, inout, whereas C# has ref. what
is the advantage of the D way?
Mar 06 2004
parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
"imr1984" <imr1984_member pathlink.com> wrote in message
news:c2cqmc$8nr$1 digitaldaemon.com...
| why does D have the reference modifiers in, out, inout, whereas C# has ref.
what
| is the advantage of the D way?

from the doc:
The reasons to have them are:
  a.. The function declaration makes it clear what the inputs and outputs to the
function are.
  b.. It eliminates the need for IDL as a separate language.
  c.. It provides more information to the compiler, enabling more error checking
and possibly better code generation.
  d.. It (perhaps?) eliminates the need for reference (&) declarations.
I can't actually find a definition of what in/inout/out do. I guess it's clear
from the
names and the examples but it would be nice to have more details in there.

-Ben
Mar 06 2004
parent =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= <sigbjorn lundolsen.net> writes:
Ben Hinkle wrote:
 "imr1984" <imr1984_member pathlink.com> wrote in message
 news:c2cqmc$8nr$1 digitaldaemon.com...
 | why does D have the reference modifiers in, out, inout, whereas C# has ref.
 what
 | is the advantage of the D way?
 
 from the doc:
 The reasons to have them are:
   a.. The function declaration makes it clear what the inputs and outputs to
the
 function are.
   b.. It eliminates the need for IDL as a separate language.
   c.. It provides more information to the compiler, enabling more error
checking
 and possibly better code generation.
   d.. It (perhaps?) eliminates the need for reference (&) declarations.
 I can't actually find a definition of what in/inout/out do. I guess it's clear
 from the
 names and the examples but it would be nice to have more details in there.
 
 -Ben
 
 

afaik, in provides a copy of the variable, inout a reference to a variable, and out a reference to a variable that has been set to its default value. But I May Be Wrong. :-o Cheers, Sigbjørn Lund Olsen
Mar 08 2004