Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
October 26, 2006 Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
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
|
October 26, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Wolfgang Draxinger | 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 |
October 26, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote: > It is known: digitalmars.D.bugs/763 Ah, thanks for the heads up. 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 |
October 26, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Wolfgang Draxinger | 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.
|
October 26, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 |
October 26, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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
|
October 27, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | 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.
|
October 27, 2006 Re: Why is the identifier "printf" known by the frontend? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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
|
Copyright © 1999-2021 by the D Language Foundation