digitalmars.D.bugs - ulong is not 64 bit long?
- Tiago Gasiba (16/16) Oct 17 2005 Hi all,
- Don Clugston (4/16) Oct 17 2005 ulong is definitely 64 bits, it's faked on 32 bit CPUs.
- Tiago Gasiba (35/53) Oct 17 2005 Hi!
- Walter Bright (3/3) Oct 17 2005 Use %llu to print a C "long long", which is the equivalent of a D "long"...
- Tiago Gasiba (5/5) Oct 17 2005 So, everything works fine now, even printf("%llu\n",ulong.max), of cours...
- Oskar Linde (4/7) Oct 17 2005 Isn't it time to replace printf by writef et.al. as default imported sym...
- JT (2/9) Oct 17 2005
- Ivan Senji (2/15) Oct 17 2005
- JT (5/23) Oct 17 2005 Because they are very different creatures. Just because you have no need...
- Unknown W. Brackets (4/8) Oct 17 2005 No, I think he just means making it so printf has to be imported (like
- JT (3/14) Oct 17 2005 Oh my mistake, I thought he was talking about just replacing the printf
- Ivan Senji (4/21) Oct 17 2005 No problem :) The printf has it's place and i agree someone might need
- Ameer Armaly (3/18) Oct 17 2005 I agree
- Sean Kelly (7/10) Oct 18 2005 For those who insist on using printf, the C standard does supply a host ...
- Tiago Gasiba (11/26) Oct 19 2005 What got me confused in the first place is the fact that the "long long"...
- Sean Kelly (6/11) Oct 19 2005 It confuses me too sometimes :) What helps me remember is that I consid...
Hi all, Is ulong 64bit or not? I'm SuSE 10.0 on a 32bit machine. On this page [http://www.digitalmars.com/d/type.html] we can see that ulong should be 64bit long. With gcc we have the unsigned long long which, although the machine might not be true 64bit, the data type is still 64 bit. i.e. gcc compiles correctly on a 64bit machine and fakes on a 32bit machine. Why is ulong.max only 2^32-1 ?? Is this a bug? Thanks! Best Regards, Tiago Gasiba -- Tiago Gasiba (MSc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.
Oct 17 2005
Tiago Gasiba wrote:Hi all, Is ulong 64bit or not? I'm SuSE 10.0 on a 32bit machine. On this page [http://www.digitalmars.com/d/type.html] we can see that ulong should be 64bit long. With gcc we have the unsigned long long which, although the machine might not be true 64bit, the data type is still 64 bit. i.e. gcc compiles correctly on a 64bit machine and fakes on a 32bit machine. Why is ulong.max only 2^32-1 ?? Is this a bug? Thanks!ulong is definitely 64 bits, it's faked on 32 bit CPUs. ulong.max == 2^64-1 on DMD - WinXP. Are you using DMD-Linux or DMC ?
Oct 17 2005
Hi! I'm using dmd on Linux with "gcc (GCC) 4.0.2 20050901 (prerelease)(SUSE Linux)" and D version is Digital Mars D Compiler v0.136 Here it goes: test.d: ------- code ------- import std.c.stdio; import std.c.stdlib; int main( ){ printf("%lu\n",ulong.max); return 0; } ------- code ------- dmd -w test.d ./test 4294967295 (answer = 2^32-1 !!!) Even worse is this: ------- code ------- import std.c.stdio; import std.c.stdlib; int main( ){ ulong X = 0xffff000000000000L; printf("%lu\n",X); return 0; } ------- code ------- dmd test.d - no compiler errors ./test 0 (answer = 0!!!) Thanks, Tiago Don Clugston wrote:Tiago Gasiba wrote:-- Tiago Gasiba (MSc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.Hi all, Is ulong 64bit or not? I'm SuSE 10.0 on a 32bit machine. On this page [http://www.digitalmars.com/d/type.html] we can see that ulong should be 64bit long. With gcc we have the unsigned long long which, although the machine might not be true 64bit, the data type is still 64 bit. i.e. gcc compiles correctly on a 64bit machine and fakes on a 32bit machine. Why is ulong.max only 2^32-1 ?? Is this a bug? Thanks!ulong is definitely 64 bits, it's faked on 32 bit CPUs. ulong.max == 2^64-1 on DMD - WinXP. Are you using DMD-Linux or DMC ?
Oct 17 2005
Use %llu to print a C "long long", which is the equivalent of a D "long". %lu will print a C "long", which is only 32 bits. Or, use std.stdio.writefln(X).
Oct 17 2005
So, everything works fine now, even printf("%llu\n",ulong.max), of course! Or, better said, it allways worked fine :) ... Thanks! Tiago Gasiba (MSc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.
Oct 17 2005
In article <dj0g9l$elk$1 digitaldaemon.com>, Walter Bright says...Use %llu to print a C "long long", which is the equivalent of a D "long". %lu will print a C "long", which is only 32 bits. Or, use std.stdio.writefln(X).Isn't it time to replace printf by writef et.al. as default imported symbols, or remove the default import of printf? /Oskar
Oct 17 2005
No. That would be a Very Bad Idea. Oskar Linde wrote:Isn't it time to replace printf by writef et.al. as default imported symbols, or remove the default import of printf? /Oskar
Oct 17 2005
JT wrote:No. That would be a Very Bad Idea.Why? I think it would be a great idea.Oskar Linde wrote:Isn't it time to replace printf by writef et.al. as default imported symbols, or remove the default import of printf? /Oskar
Oct 17 2005
Because they are very different creatures. Just because you have no need for printf doesnt mean you should take it away from me. You are basically talking about 'censoring' portions of the standard c libraries. huh? Ivan Senji wrote:JT wrote:No. That would be a Very Bad Idea.Why? I think it would be a great idea.Oskar Linde wrote:Isn't it time to replace printf by writef et.al. as default imported symbols, or remove the default import of printf? /Oskar
Oct 17 2005
No, I think he just means making it so printf has to be imported (like every other C function) which is not the case currently (since it is automatically imported/defined in object.d.) -[Unknown]Because they are very different creatures. Just because you have no need for printf doesnt mean you should take it away from me. You are basically talking about 'censoring' portions of the standard c libraries. huh?
Oct 17 2005
Oh my mistake, I thought he was talking about just replacing the printf with a writef. Sorry. I think I need sleep. heh Unknown W. Brackets wrote:No, I think he just means making it so printf has to be imported (like every other C function) which is not the case currently (since it is automatically imported/defined in object.d.) -[Unknown]Because they are very different creatures. Just because you have no need for printf doesnt mean you should take it away from me. You are basically talking about 'censoring' portions of the standard c libraries. huh?
Oct 17 2005
JT wrote:Oh my mistake, I thought he was talking about just replacing the printf with a writef. Sorry. I think I need sleep. hehNo problem :) The printf has it's place and i agree someone might need it (although in my eyes printf can not compete with writef), but default importing it shouldn't be done.Unknown W. Brackets wrote:No, I think he just means making it so printf has to be imported (like every other C function) which is not the case currently (since it is automatically imported/defined in object.d.) -[Unknown]Because they are very different creatures. Just because you have no need for printf doesnt mean you should take it away from me. You are basically talking about 'censoring' portions of the standard c libraries. huh?
Oct 17 2005
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dj0t1p$pq0$1 digitaldaemon.com...JT wrote:I agreeNo. That would be a Very Bad Idea.Why? I think it would be a great idea.Oskar Linde wrote:Isn't it time to replace printf by writef et.al. as default imported symbols, or remove the default import of printf? /Oskar
Oct 17 2005
In article <dj0g9l$elk$1 digitaldaemon.com>, Walter Bright says...Use %llu to print a C "long long", which is the equivalent of a D "long". %lu will print a C "long", which is only 32 bits. Or, use std.stdio.writefln(X).For those who insist on using printf, the C standard does supply a host of pre-done format strings in inttypes.h in an attempt to avoid these mistakes. Probably more useful as a reference than for actual use in a D project, but I've just added them to Ares for the sake of completeness: http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/inttypes.d Sean
Oct 18 2005
Sean Kelly hat geschrieben:In article <dj0g9l$elk$1 digitaldaemon.com>, Walter Bright says...What got me confused in the first place is the fact that the "long long" in C is simply "long" in D, and I forgot for a second the fact that the D printf is a wrapper to the C printf, i.e. this function was not rewritten in D to match the new data types... Shame on me! :) Best, Tiago -- Tiago Gasiba (MSc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.Use %llu to print a C "long long", which is the equivalent of a D "long". %lu will print a C "long", which is only 32 bits. Or, use std.stdio.writefln(X).For those who insist on using printf, the C standard does supply a host of pre-done format strings in inttypes.h in an attempt to avoid these mistakes. Probably more useful as a reference than for actual use in a D project, but I've just added them to Ares for the sake of completeness: http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/inttypes.d Sean
Oct 19 2005
In article <dj4td4$15lu$1 digitaldaemon.com>, Tiago Gasiba says...What got me confused in the first place is the fact that the "long long" in C is simply "long" in D, and I forgot for a second the fact that the D printf is a wrapper to the C printf, i.e. this function was not rewritten in D to match the new data types... Shame on me! :)It confuses me too sometimes :) What helps me remember is that I consider 'int' to be the type in C whose size is most likely to vary, so the standard size-based progression is: char, short, long, long long. It's just too bad that 'long long' has such an unwieldy name. Sean
Oct 19 2005