digitalmars.D.learn - Language subset for printing
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail hotmail.com> (8/8) Dec 20 2013 How big of a subset of D would a compiler need to use writeln? I
- Adam D. Ruppe (9/12) Dec 20 2013 writeln is pretty complex and using it pulls in a lot of Phobos
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail hotmail.com> (4/9) Dec 20 2013 int printf(in char* format, ...);
- Adam D. Ruppe (17/18) Dec 20 2013 Not intrinsic, just an extern library function.
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail hotmail.com> (6/7) Dec 20 2013 Well that answered more than my question. That's pretty useful
- Adam D. Ruppe (33/35) Dec 20 2013 cool. Also make note of the "extern(C):" on line 30 of that file:
How big of a subset of D would a compiler need to use writeln? I managed to track stdout to file. At the very least it seems to require templates and type tuples. Or will everything in stdio and file be needed, and perhaps thing in other files as well? Is there possibly an easier way to write to stdout? Calling printf in some C code perhaps? We'd like to start out with as small a subset as possible, but looking at return codes only is not particularly appealing. :3
Dec 20 2013
On Saturday, 21 December 2013 at 01:09:31 UTC, Casper Færgemand wrote:How big of a subset of D would a compiler need to use writeln?writeln is pretty complex and using it pulls in a lot of Phobos too.Is there possibly an easier way to write to stdout? Calling printf in some C code perhaps?Just call printf in D! import core.stdc.stdio; void main() { printf("hello world!\n"); }
Dec 20 2013
On Saturday, 21 December 2013 at 01:18:55 UTC, Adam D. Ruppe wrote:Just call printf in D! import core.stdc.stdio; void main() { printf("hello world!\n"); }int printf(in char* format, ...); I take it that means it's intrinsic?
Dec 20 2013
On Saturday, 21 December 2013 at 01:39:29 UTC, Casper Færgemand wrote:I take it that means it's intrinsic?Not intrinsic, just an extern library function. D can call any C function by copy/pasting the declaration and adding extern(C). for example, on Linux, you can do: extern(C) void write(int, char*, size_t); void main() { write(1, "hello\n", 6); } and that will work too. Similarly, on Windows, you can do: extern(Windows) int MessageBoxA(void*, const char*, const char*, int); void main() { MessageBoxA(null, "hello", "message", 0); } and call operating system functions that way.
Dec 20 2013
On Saturday, 21 December 2013 at 01:47:07 UTC, Adam D. Ruppe wrote:snipWell that answered more than my question. That's pretty useful actually. Having skimmed core.stdc.stdio.d now, it's seems pretty manageable to parse, so we'll go with that. Thankies. :3
Dec 20 2013
On Saturday, 21 December 2013 at 01:57:50 UTC, Casper Færgemand wrote:Having skimmed core.stdc.stdio.d now, it's seems pretty manageable to parse, so we'll go with that. Thankies. :3cool. Also make note of the "extern(C):" on line 30 of that file: the colon applies that thing to everything after it, so the whole file is extern(C) (and nothrow and system, unless overridden later0 Also, the druntime import names follow a simple pattern: core.stdc.* -> #include<*.h> in C. so stdio.h is core.stdc.stdio, stdlib.h is core.stdc.stdlib, and so on. This only covers standard C functions, some C includes won't be there since they are non-standard extensions. There's also includes for other operating systems in core.sys.OS_NAME.FILE so import core.sys.posix.unistd; is #include<unistd.h> in C on Posix systems (linux, etc.) core.sys.linux.* is Linus specific extensions. core.sys.posix.sys.socket == #include<sys/socket.h> And there's also core.sys.windows.windows for Windows stuff, though this is really incomplete. So if you do much work with the Win32 API you'll want to download the more complete bindings http://www.dsource.org/projects/bindings/browser/trunk/win32 There's a bunch of other C libs done in here too: https://github.com/D-Programming-Deimos Or, you can avoid doing the modules by just copy/pasting the extern(C) definitions you need to call yourself. That can get a bit tricky translating macros and structs from C, you'll have to be sure to get the types right (A "long" in C isn't the same as a "long" in D for instance), but this isn't too hard either. So if something isn't already done in the deimos collection, you can still use the C libraries (or other C files you write) just by getting those function prototypes done like i did in my last message.
Dec 20 2013