Different results for int and long alias

Lionello Lunesu lio at lunesu.remove.com
Sat Mar 3 22:51:55 PST 2007


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.

L.


More information about the Digitalmars-d-learn mailing list