D - C and D code in one file
- J Anderson (18/18) Jan 27 2004 Is there a way (without using pre-processors) to have both C/C++ and D
-
Stewart Gordon
(22/27)
Jan 27 2004
- J Anderson (4/27) Jan 28 2004 This is an interesting hack.
- Stewart Gordon (11/16) Jan 29 2004 While it was 27/1/04 5:17 pm throughout the UK, Stewart Gordon sprinkled...
- Russ Lewis (37/58) Jan 27 2004 I wonder if we could add some syntax somewhat like the asm syntax:
- J Anderson (12/71) Jan 27 2004 Not exactly what I had in mind. However I must say I had this idea a
- Ben Hinkle (4/6) Jan 27 2004 One language to rule them all, One language to find them,
- C (4/10) Jan 27 2004 Nice ;).
Is there a way (without using pre-processors) to have both C/C++ and D versions of code in one file. I was just thinking that parhaps some slight moderations to comments (or a new comment) could aid in this. Having both C++ and D code in one file could reduce redundancy if something needs to be written for both. ie something like (this does not currently work) /*+/ class x(T) //D code { } /+*/ /*/+*/ template <T> class x //C++ code { } /*+/*/ There's probably a better way of doing this (which I hope will be suggested), but I think you get the idea. -- -Anderson: http://badmama.com.au/~anderson/
Jan 27 2004
While it was 27/1/04 4:24 pm throughout the UK, J Anderson sprinkled little black dots on a white screen, and they fell thus:Is there a way (without using pre-processors) to have both C/C++ and D versions of code in one file. I was just thinking that parhaps some slight moderations to comments (or a new comment) could aid in this. Having both C++ and D code in one file could reduce redundancy if something needs to be written for both.<snip> int dummy = 0 /+ 1; int main() { printf("This is C!\n"); return 0; } /* +/; int main() { printf("This is D!" \n); return 0; } */ This, of course, relies on the simplism described in thread "[Style Guide] Nested Comments". Not to mention that you'd generally need to either change the extension from time to time or use Unix file-linking. 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.
Jan 27 2004
Stewart Gordon wrote:While it was 27/1/04 4:24 pm throughout the UK, J Anderson sprinkled little black dots on a white screen, and they fell thus:This is an interesting hack. -- -Anderson: http://badmama.com.au/~anderson/Is there a way (without using pre-processors) to have both C/C++ and D versions of code in one file. I was just thinking that parhaps some slight moderations to comments (or a new comment) could aid in this. Having both C++ and D code in one file could reduce redundancy if something needs to be written for both.<snip> int dummy = 0 /+ 1; int main() { printf("This is C!\n"); return 0; } /* +/; int main() { printf("This is D!" \n); return 0; } */ This, of course, relies on the simplism described in thread "[Style Guide] Nested Comments". Not to mention that you'd generally need to either change the extension from time to time or use Unix file-linking. Stewart.
Jan 28 2004
While it was 27/1/04 5:17 pm throughout the UK, Stewart Gordon sprinkled little black dots on a white screen, and they fell thus: <snip>int main() { printf("This is D!" \n); return 0; } */Oops, this should be // */ at the end. 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.
Jan 29 2004
I wonder if we could add some syntax somewhat like the asm syntax: language(C) { ...C source... }; At first pass, I would assume that the C source would be passed without modification into the system's C compiler; the D compiler would then automatically link the C compiler's .o file with the D compiler's .o file. But even cooler, what if the C source file automagically got prototypes for all of the extern(C) declarations in the D source? Imagine this D source file: module foo; extern(C) int foo(byte *bar, byte* baz) { ... }; extern(C) int C_function(); int func(); /* since this is not extern(C), * the language(C) won't see it */ language(C) { extern int C_function() { ... foo(... , ...); ... } } The D compiler passes this source into the C compiler: int foo(char *bar, char* baz) { ... }; int C_function(); extern int C_function() { ... foo(... , ...); ... } (Note that the D compiler is smart enough to turn the 'byte' arguments into the C equivalent 'char'.). This idea gets especially exciting when you invision that later compilers might support not just extern(C)/language(C), but extern(Java)/language(Java), extern(perl)/language(perl), and maybe more. Thoughts? J Anderson wrote:Is there a way (without using pre-processors) to have both C/C++ and D versions of code in one file. I was just thinking that parhaps some slight moderations to comments (or a new comment) could aid in this. Having both C++ and D code in one file could reduce redundancy if something needs to be written for both. ie something like (this does not currently work) /*+/ class x(T) //D code { } /+*/ /*/+*/ template <T> class x //C++ code { } /*+/*/ There's probably a better way of doing this (which I hope will be suggested), but I think you get the idea.
Jan 27 2004
Russ Lewis wrote:I wonder if we could add some syntax somewhat like the asm syntax: language(C) { ...C source... }; At first pass, I would assume that the C source would be passed without modification into the system's C compiler; the D compiler would then automatically link the C compiler's .o file with the D compiler's .o file. But even cooler, what if the C source file automagically got prototypes for all of the extern(C) declarations in the D source? Imagine this D source file: module foo; extern(C) int foo(byte *bar, byte* baz) { ... }; extern(C) int C_function(); int func(); /* since this is not extern(C), * the language(C) won't see it */ language(C) { extern int C_function() { ... foo(... , ...); ... } } The D compiler passes this source into the C compiler: int foo(char *bar, char* baz) { ... }; int C_function(); extern int C_function() { ... foo(... , ...); ... } (Note that the D compiler is smart enough to turn the 'byte' arguments into the C equivalent 'char'.). This idea gets especially exciting when you invision that later compilers might support not just extern(C)/language(C), but extern(Java)/language(Java), extern(perl)/language(perl), and maybe more. Thoughts? J Anderson wrote:Not exactly what I had in mind. However I must say I had this idea a couple of years back before I even knew about D, but I guess it's not new. I discussed it with some friends and they seemed to hate the idea. Although I think I'd be really cool to switch from language to language in code, for whatever language is suited best for the languages, but it's not quite the same. But this is something I strongly doubt, would never happen in the D language itself. It would need to be in a meta language. -- -Anderson: http://badmama.com.au/~anderson/Is there a way (without using pre-processors) to have both C/C++ and D versions of code in one file. I was just thinking that parhaps some slight moderations to comments (or a new comment) could aid in this. Having both C++ and D code in one file could reduce redundancy if something needs to be written for both. ie something like (this does not currently work) /*+/ class x(T) //D code { } /+*/ /*/+*/ template <T> class x //C++ code { } /*+/*/ There's probably a better way of doing this (which I hope will be suggested), but I think you get the idea.
Jan 27 2004
But this is something I strongly doubt, would never happen in the D language itself. It would need to be in a meta language.One language to rule them all, One language to find them, One language to bring them all and in the darkness bind them. sorry, I couldn't resist. -Ben
Jan 27 2004
Nice ;). C "Ben Hinkle" <bhinkle4 juno.com> wrote in message news:bv6fif$7a$1 digitaldaemon.com...But this is something I strongly doubt, would never happen in the D language itself. It would need to be in a meta language.One language to rule them all, One language to find them, One language to bring them all and in the darkness bind them. sorry, I couldn't resist. -Ben
Jan 27 2004