www.digitalmars.com         C & C++   DMDScript  

D - inout and C

reply Andy Friesen <andy ikagames.com> writes:
Maybe this is one of those scary implementation details that we're not 
supposed to think about, but it's a corner of the language that should 
be nailed down. (even if it is nailed down as being implementation 
dependant)

Does D stipulate that inout passes by pointer, specifically with 
extern(C) functions?  I'm messing around with DWT a bit, and it'd be 
nice to be able to say SendMessageW(inout MSG msg, ...); instead of 
resorting to pointers and the like. (that being said, I don't really 
have an opinion on the matter one way or another, I'd just like to know)

  -- andy
Mar 30 2004
parent reply "Walter" <walter digitalmars.com> writes:
"Andy Friesen" <andy ikagames.com> wrote in message
news:c4dkj1$852$1 digitaldaemon.com...
 Maybe this is one of those scary implementation details that we're not
 supposed to think about, but it's a corner of the language that should
 be nailed down. (even if it is nailed down as being implementation
 dependant)

 Does D stipulate that inout passes by pointer, specifically with
 extern(C) functions?  I'm messing around with DWT a bit, and it'd be
 nice to be able to say SendMessageW(inout MSG msg, ...); instead of
 resorting to pointers and the like. (that being said, I don't really
 have an opinion on the matter one way or another, I'd just like to know)
My opinion is that inout and out are D features, not C features, and so if you are interfacing to a C function written in C, then use the explicit C pointer syntax. Matthew Wilson disagrees with me on this point, he argues that you can improve on the C interface by using out and inout where appropriate (yes, they are implemented as a pointer).
Mar 31 2004
parent "Matthew" <matthew stlsoft.org> writes:
"Walter" <walter digitalmars.com> wrote in message
news:c4gi7n$1vtf$1 digitaldaemon.com...
 "Andy Friesen" <andy ikagames.com> wrote in message
 news:c4dkj1$852$1 digitaldaemon.com...
 Maybe this is one of those scary implementation details that we're not
 supposed to think about, but it's a corner of the language that should
 be nailed down. (even if it is nailed down as being implementation
 dependant)

 Does D stipulate that inout passes by pointer, specifically with
 extern(C) functions?  I'm messing around with DWT a bit, and it'd be
 nice to be able to say SendMessageW(inout MSG msg, ...); instead of
 resorting to pointers and the like. (that being said, I don't really
 have an opinion on the matter one way or another, I'd just like to know)
My opinion is that inout and out are D features, not C features, and so if you are interfacing to a C function written in C, then use the explicit C pointer syntax. Matthew Wilson disagrees with me on this point, he argues that you can improve on the C interface by using out and inout where appropriate (yes, they are implemented as a pointer).
I do that in my mappings of libs, and it improves safety. I also do it in coming out at some point on it, but I can't remember when. Of course, if you do it wrong, you've opened a giant can of worms. ;)
Apr 01 2004