digitalmars.D - Reserved words in D and C
- Arcane Jill (12/12) Jul 20 2004 Please read this post with a sense of humor. This isn't a serious proble...
- Stewart Gordon (19/32) Jul 20 2004 Either rename the C function (if it's within your control), or write a C...
- Regan Heath (14/28) Jul 20 2004 I came across this when looking to convert the openssl C structures to D...
- Charlie (8/38) Jul 20 2004 You can rename it 'versionInt' or something, its name doesnt matter, how...
- Mike Parker (14/25) Jul 21 2004 They aren't the same within D, nor are they the same within C, but they
- J C Calvarese (22/37) Jul 20 2004 Assuming a person didn't have access to the C source (which would take
- teqDruid (3/18) Jul 20 2004 It'd be nice if a simple alias could be used to fix this, but somehow I
-
Carlos Santander B.
(33/33)
Jul 21 2004
"Arcane Jill"
escribió en el mensaje
Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun. Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout? Jill
Jul 20 2004
Arcane Jill wrote:Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun. Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout?Either rename the C function (if it's within your control), or write a C wrapper to effectively rename it. This reminds me of an idea I've had for a while: something like extern("_inout") int inOut(int x); The idea is that the actual mangled name would be specified in extern(...), and it would be mapped to a function name of the programmer's in the D code. This could be used to interface a wider range of foreign codes, e.g. the Sun F90 compiler puts dots in mangled function names, preventing them from being interfaced for the time being. Calling convention for this syntax? Well, I guess plain C would be sensible - I'm not sure if it's accurate to say that C is the simplest, and that other CCs can be expressed in terms of it. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jul 20 2004
On Tue, 20 Jul 2004 09:31:46 +0000 (UTC), Arcane Jill <Arcane_member pathlink.com> wrote:Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun. Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout?I came across this when looking to convert the openssl C structures to D. struct { int version; .. etc .. } 'version' is a D keyword. What can be done in this case? Perhaps inside an extern (C) block certain keywords aren't necessary and could be disabled/ignored? I'm not sure 'version' is one of them however. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 20 2004
You can rename it 'versionInt' or something, its name doesnt matter, however its offset in the struct does :),i.e. struct f{ int x; int y; } is not the same as struct f{ int y; int x; } Their positions will be swapped, im thinking its found by offset alone ?. Charlie In article <opsbgjeunl5a2sq9 digitalmars.com>, Regan Heath says...On Tue, 20 Jul 2004 09:31:46 +0000 (UTC), Arcane Jill <Arcane_member pathlink.com> wrote:Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun. Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout?I came across this when looking to convert the openssl C structures to D. struct { int version; .. etc .. } 'version' is a D keyword. What can be done in this case? Perhaps inside an extern (C) block certain keywords aren't necessary and could be disabled/ignored? I'm not sure 'version' is one of them however. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 20 2004
Charlie wrote:You can rename it 'versionInt' or something, its name doesnt matter, however its offset in the struct does :),i.e. struct f{ int x; int y; } is not the same as struct f{ int y; int x; } Their positions will be swapped, im thinking its found by offset alone ?.They aren't the same within D, nor are they the same within C, but they *are* the same when you compare the D definition to the C definition. D sees an int followed by an int, C sees an int followed by an int. So in D: struct f{int x, int y}; f ff; ff.x = 10; ff.y = 11; someCFunction(&ff); When ff is passed to the C function, the first value will still be 10 and the second value will still be 11 although the names are reversed. The name only refers to the memory offset, not the value. So ff.x in D is the same offset as ff.y in C.
Jul 21 2004
Arcane Jill wrote:Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun.:)Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout? JillAssuming a person didn't have access to the C source (which would take away all of the fun), I wonder if you could create a .def file to work around this. Maybe something like this? mydll.def --------- LIBRARY mydll EXETYPE NT SUBSYSTEM WINDOWS EXPORTS _InOut 4 = inout Then use D code like this: extern(C) int InOut(int x); void main() { printf("%d\n", InOut(-1)); } I think it would work, but I haven't tested it. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jul 20 2004
It'd be nice if a simple alias could be used to fix this, but somehow I doubt dmd's parser would make this easy to do. On Tue, 20 Jul 2004 09:31:46 +0000, Arcane Jill wrote:Please read this post with a sense of humor. This isn't a serious problem, so I'm just posting it for fun. Just because something is a reserved word in D, doesn't necessarily make it a reserved word in C. How may I call this C function, whose name happens to be inout? Jill
Jul 20 2004
"Arcane Jill" <Arcane_member pathlink.com> escribió en el mensaje news:cdioq2$1aid$1 digitaldaemon.com | Please read this post with a sense of humor. This isn't a serious problem, so | I'm just posting it for fun. | | | Just because something is a reserved word in D, doesn't necessarily make it a | reserved word in C. How may I call this C function, whose name happens to be | inout? | | Jill My 2 cents: I would write a C wrapper around it and use the wrapper in D. /* wrapper.c */ int inout(int x); int InOut(int x) { return inout(x); } // AJ_module.d extern (C) int InOut(int x); void main () { printf("%d\n", InOut(-1)); } ----------------------- Carlos Santander Bernal
Jul 21 2004