D - inout and C
- Andy Friesen <andy ikagames.com> Mar 30 2004
- "Walter" <walter digitalmars.com> Mar 31 2004
- "Matthew" <matthew stlsoft.org> Apr 01 2004
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
"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
"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 other languages - C#, IDL, etc. - for the same reason. IIRC I've a DDJ tip 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








"Matthew" <matthew stlsoft.org>