Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 18, 2004 in and inout, are they different? | ||||
---|---|---|---|---|
| ||||
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 |
April 18, 2004 Re: in and inout, are they different? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tydr Schnubbis | 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
|
April 18, 2004 Re: in and inout, are they different? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tydr Schnubbis | 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.
Tor
|
April 24, 2004 Re: in and inout, are they different? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tydr Schnubbis | 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
|
Copyright © 1999-2021 by the D Language Foundation