www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why is the identifier "printf" known by the frontend?

reply Wolfgang Draxinger <wdraxinger darkstargames.de> writes:
Until now I always imported std.stdio to get printf, but today I
compiled a program where I forgot that, so fwrite, fread and the
other std.c.stdio functions were missing. But not printf;
obviously it is made avaliable by the compiler, which I don't
understand, since eventually you don't want to use printf in
your programs (for whatever reason) or want to implement a
alternative.

What is the reason for that? "import std.stdio" is not a real
difficult thing to type.

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith jabber.org, ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
Oct 26 2006
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Wolfgang Draxinger wrote:

 Until now I always imported std.stdio to get printf, but today I
 compiled a program where I forgot that, so fwrite, fread and the
 other std.c.stdio functions were missing. But not printf;
 obviously it is made avaliable by the compiler, which I don't
 understand, since eventually you don't want to use printf in
 your programs (for whatever reason) or want to implement a
 alternative.
It's in object.d. And that's a bug.
 What is the reason for that? "import std.stdio" is not a real
 difficult thing to type.
It is known: digitalmars.D.bugs/763 --anders
Oct 26 2006
parent Wolfgang Draxinger <wdraxinger darkstargames.de> writes:
Anders F Bj=C3=B6rklund wrote:

 It is known: digitalmars.D.bugs/763
Ah, thanks for the heads up. Wolfgang Draxinger --=20 E-Mail address works, Jabber: hexarith jabber.org, ICQ: 134682867 GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
Oct 26 2006
prev sibling parent reply Walter Bright <newshound digitalmars.com> writes:
Wolfgang Draxinger wrote:
 What is the reason for that? "import std.stdio" is not a real
 difficult thing to type.
Because I find it verrryy handy in writing minimal test cases. writefln, in order to work, requires much of D and Phobos to be working properly. printf, being part of the C library, doesn't require any of Phobos and very little of D to work, so it's handy when things are broken.
Oct 26 2006
next sibling parent Wolfgang Draxinger <wdraxinger darkstargames.de> writes:
Walter Bright wrote:

 Because I find it verrryy handy in writing minimal test cases.
 writefln, in order to work, requires much of D and Phobos to be
 working properly. printf, being part of the C library, doesn't
 require any of Phobos and very little of D to work, so it's
 handy when things are broken.
Honestly: I don't like it. And the function prototype is so simple that it's written down with ease it you really need it. int printf(char*, ...); The problem I have with it, that printf is not really a keyword like in say scripting languages like python. It's part of the C stdio library, but on some systems not gauranteed to be really there. I admit that it's oftenly handy to have a quick hands on print for debugging. But it should really be considered, if it wasn't better to use some more D specific concept then. And in some situations you don't even have printf avaliable. E.g. my 3D engine has something compareable to pty of Unix, to which consoles, message output and so on can be sent to. For an ordinary printf it would not be clear, where so send it (well stdout, but this can be redirected anywhere). Wolfgang Draxinger -- E-Mail address works, Jabber: hexarith jabber.org, ICQ: 134682867 GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E
Oct 26 2006
prev sibling next sibling parent reply BCS <BCS pathilink.com> writes:
Walter Bright wrote:
 Wolfgang Draxinger wrote:
 What is the reason for that? "import std.stdio" is not a real
 difficult thing to type.
Because I find it verrryy handy in writing minimal test cases. writefln, in order to work, requires much of D and Phobos to be working properly. printf, being part of the C library, doesn't require any of Phobos and very little of D to work, so it's handy when things are broken.
Could this be put under a compiler switch? -dbg compiler debug mode
Oct 26 2006
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
BCS wrote:
 Walter Bright wrote:
 Wolfgang Draxinger wrote:
 What is the reason for that? "import std.stdio" is not a real
 difficult thing to type.
Because I find it verrryy handy in writing minimal test cases. writefln, in order to work, requires much of D and Phobos to be working properly. printf, being part of the C library, doesn't require any of Phobos and very little of D to work, so it's handy when things are broken.
Could this be put under a compiler switch? -dbg compiler debug mode
Or just -debug=PhobosDebug (or whatever). No compiler modifications necessary. Of course, this should be turned off for the Phobos binary distributed with the compiler.
Oct 26 2006
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter Bright wrote:

 What is the reason for that? "import std.stdio" is not a real
 difficult thing to type.
Because I find it verrryy handy in writing minimal test cases. writefln, in order to work, requires much of D and Phobos to be working properly. printf, being part of the C library, doesn't require any of Phobos and very little of D to work, so it's handy when things are broken.
But the "import std.c.stdio;" isn't so very hard to type either ? It's not so much about the usage of good ole printf, as it is about the placement of printf in the "object.d" file. But you knew that... --anders
Oct 27 2006