FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

In out and ref

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
yuumei



Joined: 15 Nov 2007
Posts: 1
Location: UK

PostPosted: Thu Nov 15, 2007 9:53 am    Post subject: In out and ref Reply with quote

Hey!
I just started with D and I love it!

Would anyone be able to tell me the difference between in, out, ref and inout.

Code:
import std.stdio;
void inTesting(in int a2, out int b2, ref int c2, int d2, inout int e2) {
   writefln("%x, %x, %x, %x, %x", &a2, &b2, &c2, &d2, &e2);
}
int main() {
   int a;
   int b;
   int c;
   int d;
   int e;
   writefln("%x, %x, %x, %x, %x", &a, &b, &c, &d, &e);
   inTesting(a, b, c, d, e);
   return 0;
}


I have tried this and it seems that 'in' makes a copy and 'out' is like a reference. But I cant figure out the rest.
_________________
^^*
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Thu Nov 15, 2007 3:54 pm    Post subject: Reply with quote

For D/1.x:
'in' is just the default.
'out' is pass-by-reference with the variable reset to its type's .init value first.
'ref' is just an (often preferred) alias for 'inout'.
'inout' is simple pass-by-reference.

For D/2.x:
Mostly the same, except 'in' is shorthand for 'final const scope' and the default method has no explicit form/symbol.
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group