www.digitalmars.com         C & C++   DMDScript  

D - Simple question

reply "Luigi" <cyberboy email.it> writes:
Hello,

I'm italian boy and I not speak a good english, then sorry :)

My question is this:

a "inout" parameters of one function, are the same that a parameteres passed
for address?

For example:

// D

void foo (inout int x);

// C++

void foo (int& x);

are equivalent?

Thank you

--
Luigi

E-mail: cyberboy email.it

May 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Luigi" <cyberboy email.it> wrote in message
news:aclr7o$o0j$1 digitaldaemon.com...

 For example:

 // D

 void foo (inout int x);

 // C++

 void foo (int& x);

 are equivalent?
Yes.
May 24 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:acm10f$t4f$1 digitaldaemon.com...
 "Luigi" <cyberboy email.it> wrote in message
 news:aclr7o$o0j$1 digitaldaemon.com...
 // D
 void foo (inout int x);
 // C++
 void foo (int& x);
 are equivalent?
Yes.
For most purposes, yes. In D, though, the parameter x gets initialized before being passed to foo(), this is not necessarilly so in C++.
May 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:acm3ck$vbc$2 digitaldaemon.com...

 For most purposes, yes. In D, though, the parameter x gets initialized
 before being passed to foo(), this is not necessarilly so in C++.
I thought that variables passed as inout arguments are _required_ to be initialized before the call... and it's out arguments which are initialized to default value; ain't I right?
May 24 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:acm6ng$12cc$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:acm3ck$vbc$2 digitaldaemon.com...

 For most purposes, yes. In D, though, the parameter x gets initialized
 before being passed to foo(), this is not necessarilly so in C++.
I thought that variables passed as inout arguments are _required_ to be initialized before the call... and it's out arguments which are initialized to default value; ain't I right?
All variables get initialized at some point, even if it is just to the default value. Inout variables get initialized by the caller, out variables get initialized by the callee. C++'s inability to distinguish between an out and an inout (or even an in) is a serious bug, leading to kludge-o-matic workarounds like IDL.
May 24 2002
parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:acn93l$2028$2 digitaldaemon.com...
 "Pavel Minayev" <evilone omen.ru> wrote in message
 news:acm6ng$12cc$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:acm3ck$vbc$2 digitaldaemon.com...

 For most purposes, yes. In D, though, the parameter x gets initialized
 before being passed to foo(), this is not necessarilly so in C++.
I thought that variables passed as inout arguments are _required_ to be initialized before the call... and it's out arguments which are initialized to default value; ain't I right?
All variables get initialized at some point, even if it is just to the default value. Inout variables get initialized by the caller, out
variables
 get initialized by the callee.

 C++'s inability to distinguish between an out and an inout (or even an in)
 is a serious bug, leading to kludge-o-matic workarounds like IDL.
Well, IDL ofcourse also serves the purpose of being language independant, so you could also write IDL compilers that generate Object Pascal header files, for example... Walter is there still any need for IDL in D, or are all constructs supported by IDL also supported by D? What do you do with the unique and ref keywords for instance? -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
May 26 2002
parent reply "Walter" <walter digitalmars.com> writes:
"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:acqivc$a3j$1 digitaldaemon.com...
 Walter is there still any need for IDL in D,
 or are all constructs supported by IDL also
 supported by D? What do you do with the
 unique and ref keywords for instance?
I don't remember what those keywords do.
Jun 05 2002
parent reply "Matthew Wilson" <mwilson nextgengaming.com> writes:
simply:

- unique says there is no aliasing elsewhere (in the walkable tree of
arguments in "this" function call) of the ptr so marked.

- ref incorporates unique, and states that the ptr so marked cannot be NULL
(or rather that it will not be NULL - it's still possible to pass NULL in
C/C++ of course)

As I said, this is a simple explanation, but captures the most interesting
features. If anyone wants to provide a fullsome explanation, be my guest ...



"Walter" <walter digitalmars.com> wrote in message
news:adlhnj$166m$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:acqivc$a3j$1 digitaldaemon.com...
 Walter is there still any need for IDL in D,
 or are all constructs supported by IDL also
 supported by D? What do you do with the
 unique and ref keywords for instance?
I don't remember what those keywords do.
Jun 05 2002
parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Matthew Wilson" <mwilson nextgengaming.com> wrote in message
news:adm69r$1pt3$1 digitaldaemon.com...
 simply:

 - unique says there is no aliasing elsewhere (in the walkable tree of
 arguments in "this" function call) of the ptr so marked.

 - ref incorporates unique, and states that the ptr so marked cannot be
NULL
 (or rather that it will not be NULL - it's still possible to pass NULL in
 C/C++ of course)

 As I said, this is a simple explanation, but captures the most interesting
 features. If anyone wants to provide a fullsome explanation, be my guest
...
 "Walter" <walter digitalmars.com> wrote in message
 news:adlhnj$166m$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:acqivc$a3j$1 digitaldaemon.com...
 Walter is there still any need for IDL in D,
 or are all constructs supported by IDL also
 supported by D? What do you do with the
 unique and ref keywords for instance?
I don't remember what those keywords do.
Basically they aid COM in the decision for marshaling code to use. Let's say you pass a circular linked list. Since you cannot pass pointers across boundaries you will have to copy the block of memory each pointer is pointing at. However you might get in an infinite loop when passing a circular linked list, so you have to check each pointer to see if you already passed it before. Using unique tells the IDL compiler that every pointer will be unique, so the extra checking code is not needed, making the marshaling faster. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Jun 09 2002
parent reply "Walter" <walter digitalmars.com> writes:
Thanks for the illumination. D doesn't have something directly comparable.

"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:ae0enc$nhq$1 digitaldaemon.com...
 "Matthew Wilson" <mwilson nextgengaming.com> wrote in message
 news:adm69r$1pt3$1 digitaldaemon.com...
 simply:

 - unique says there is no aliasing elsewhere (in the walkable tree of
 arguments in "this" function call) of the ptr so marked.

 - ref incorporates unique, and states that the ptr so marked cannot be
NULL
 (or rather that it will not be NULL - it's still possible to pass NULL
in
 C/C++ of course)

 As I said, this is a simple explanation, but captures the most
interesting
 features. If anyone wants to provide a fullsome explanation, be my guest
...
 "Walter" <walter digitalmars.com> wrote in message
 news:adlhnj$166m$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:acqivc$a3j$1 digitaldaemon.com...
 Walter is there still any need for IDL in D,
 or are all constructs supported by IDL also
 supported by D? What do you do with the
 unique and ref keywords for instance?
I don't remember what those keywords do.
Basically they aid COM in the decision for marshaling code to use. Let's say you pass a circular linked list. Since you cannot pass pointers across boundaries you will have to copy the block of memory each pointer is pointing at. However you might get in an infinite loop when passing a circular linked list, so you have to check each pointer to see if you already passed it before. Using unique tells the IDL compiler that every pointer will be unique, so the extra checking code is not needed, making the marshaling faster. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Jun 09 2002
parent "OddesE" <OddesE_XYZ hotmail.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:ae0vvr$18iq$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:ae0enc$nhq$1 digitaldaemon.com...
 "Matthew Wilson" <mwilson nextgengaming.com> wrote in message
 news:adm69r$1pt3$1 digitaldaemon.com...
 simply:

 - unique says there is no aliasing elsewhere (in the walkable tree of
 arguments in "this" function call) of the ptr so marked.

 - ref incorporates unique, and states that the ptr so marked cannot be
NULL
 (or rather that it will not be NULL - it's still possible to pass NULL
in
 C/C++ of course)

 As I said, this is a simple explanation, but captures the most
interesting
 features. If anyone wants to provide a fullsome explanation, be my
guest
 ...
 "Walter" <walter digitalmars.com> wrote in message
 news:adlhnj$166m$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:acqivc$a3j$1 digitaldaemon.com...
 Walter is there still any need for IDL in D,
 or are all constructs supported by IDL also
 supported by D? What do you do with the
 unique and ref keywords for instance?
I don't remember what those keywords do.
Basically they aid COM in the decision for marshaling code to use. Let's say you pass a circular linked list. Since you cannot pass pointers across boundaries you will have to copy the block of memory each pointer is pointing at. However you might get in an infinite loop when passing a circular linked list, so you have to check each pointer to see if you already passed it before. Using unique tells the IDL compiler that every pointer will be unique, so the extra checking code is not needed, making the marshaling faster. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
 Thanks for the illumination. D doesn't have something directly comparable.
And that makes perfect sense, COM is proprietary, D isn't. But just don't write off IDL yet... :) -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Jun 11 2002