|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
digitalmars.D - in, out and inout for function arguments
I have a program:
import std.file;
public static void foo(in int i, out int o, inout int io)
{
i++; o--; io++;
printf("foo %d, %d, %d\n", i, o, io);
}
int main (char[][] args)
{
int i1 = 1, i2 = 123, i3 = 234;
printf("before foo %d, %d, %d\n", i1, i2, i3);
foo(i1, i2, i3);
printf("after foo %d, %d, %d\n", i1, i2, i3);
return 0;
}
Why this compiles successfully with dmd compiler?
I expect 'out' parameter modification to cause error. Is it a bug in compiler
implementation or wrong usage?
Also looking at sample programs I don't find in/out usage as common?
Oct 12 2006
On Thu, 12 Oct 2006 08:46:32 +0000 (UTC), SKS wrote: Oct 12 2006
When 'inout' is used, it is usually as a compromise to improve performance. For example, it can be a performance cost to copy large structs or fixed-length arrays betwen functions, and 'inout' is a way to avoid that. Oct 12 2006
Derek Parnell wrote:Once the function gets control, it can modify the passed arguments as much as it likes, but only changes to 'in' and 'inout' arguments get fed back to the calling code. Oct 12 2006
On Thu, 12 Oct 2006 09:05:23 -0700, BCS wrote:Derek Parnell wrote:Once the function gets control, it can modify the passed arguments as much as it likes, but only changes to 'in' and 'inout' arguments get fed back to the calling code. Oct 12 2006
BCS wrote:Derek Parnell wrote:Once the function gets control, it can modify the passed arguments as much as it likes, but only changes to 'in' and 'inout' arguments get fed back to the calling code. Oct 16 2006
|