Different results for int and long alias

Andy Little andy at servocomm.freeserve.co.uk
Sun Mar 4 02:21:33 PST 2007


Lionello Lunesu Wrote:

> Andy Little wrote:
> > In the following example when I use an int in the marked section the code works as expected, however if I use a long the output is incorrect.
> > 
> > Coming from C++ I don't understand the casting system. Is this the cause or is this a bug?
> 
> "long" in D is a 64-bit integer, therefore you should use "%ld" to print 
> it using printf. Generally, try to cut back on the use of printf since 
> it doesn't check the arguments, causing many similar problems. You 
> should use writefln/writef (from std.stdio) instead. In writefln you can 
>   simply use "%s" for all types.

Great it works.. thanks.  

Presumably this means you need to provide an overload of some "toString(T)" function for your own types?

regards
Andy Little





More information about the Digitalmars-d-learn mailing list