www.digitalmars.com         C & C++   DMDScript  

D - in and inout, are they different?

reply Tydr Schnubbis <nobody nowhere.fake> writes:
Apart from the obvious difference in their intended usage, are they
different?  Does inout guarantee that a variable has been assigned to
prior to being used as an argument?  Do both inout and out guarantee
that they parameters will be assigned to inside the function? I think
C# has guarantees of this kind. Can't find this in the docs anywhere.

Tor
Apr 18 2004
next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
The 'inout' attribute essentially means pass-by-reference, 'in' is just 
there for completeness and means to use whatever the default is 
(pass-by-value for pretty much everything, pass-by-reference for 
classes).  And no they don't gurantee assignment, but since all D 
variables have a default value (.init) one could argue that they are 
technically guranteed to have something anyhow.

-C. Sauls
-Invironz

Tydr Schnubbis wrote:
 Apart from the obvious difference in their intended usage, are they
 different?  Does inout guarantee that a variable has been assigned to
 prior to being used as an argument?  Do both inout and out guarantee
 that they parameters will be assigned to inside the function? I think
 C# has guarantees of this kind. Can't find this in the docs anywhere.
 
 Tor

Apr 18 2004
prev sibling parent reply Tydr Schnubbis <nobody nowhere.fake> writes:
Tydr Schnubbis wrote:
 Apart from the obvious difference in their intended usage, are they
 different?  Does inout guarantee that a variable has been assigned to
 prior to being used as an argument?  Do both inout and out guarantee
 that they parameters will be assigned to inside the function? I think
 C# has guarantees of this kind. Can't find this in the docs anywhere.
 
 Tor

and inout. But I guess any guarantee that an inout parameter, if a variable, has been assigned to before used as an argument, would apply to in as well. I realize that being forced to assign to a variable to avoid compiler errors or warnings might be annoying if you are happy with the default value. But to have this kind of enforcement could also be very useful. Tor
Apr 18 2004
parent =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= <sigbjorn lundolsen.net> writes:
Tydr Schnubbis wrote:
 Tydr Schnubbis wrote:
 
 Apart from the obvious difference in their intended usage, are they
 different?  Does inout guarantee that a variable has been assigned to
 prior to being used as an argument?  Do both inout and out guarantee
 that they parameters will be assigned to inside the function? I think
 C# has guarantees of this kind. Can't find this in the docs anywhere.

 Tor

Sorry, I meant to ask about the difference between out and inout, not in and inout. But I guess any guarantee that an inout parameter, if a variable, has been assigned to before used as an argument, would apply to in as well. I realize that being forced to assign to a variable to avoid compiler errors or warnings might be annoying if you are happy with the default value. But to have this kind of enforcement could also be very useful.

'out' will set the variable to its .init value. So if you pass a float with 0.75 as an out, it will be set to NaN as it is passed to the function. inout doesn't do this, the value of 0.75 is left alone. Cheers, Sigbjørn Lund Olsen
Apr 24 2004