Windows and long long

2005-02-20 Thread Hrvoje Niksic
Does MSVC support long long?  If not, how does one...

 * print __int64 values?  I assume printf(%lld, ...) doesn't work?

 * retrieve __int64 values from strings?  I assume there is no
   strtoll?

I'm asking because I noticed that my LFS patch kind of depends on long
long on machines with LFS.


Re: Windows and long long

2005-02-20 Thread Gisle Vanem
Hrvoje Niksic wrote:
Does MSVC support long long?  If not, how does one...
No, it has a '__int64' built-in.
* print __int64 values?  I assume printf(%lld, ...) doesn't work?
Correct, use %I64d for signed 64-bit and %I64u for unsigned.
* retrieve __int64 values from strings?  I assume there is no
  strtoll?
No, but MSVC7 has a 
 __int64 __cdecl _strtoi64(const char *str, char **endptr, int base); 

MingW and Watcom have strtoll(). For MSVC6 one could use
sscanf (str,%I64d,val);
--gv


Re: Windows and long long

2005-02-20 Thread Hrvoje Niksic
Gisle Vanem [EMAIL PROTECTED] writes:

 Hrvoje Niksic wrote:

 Does MSVC support long long?  If not, how does one...

 No, it has a '__int64' built-in.
  
 * print __int64 values?  I assume printf(%lld, ...) doesn't work?

 Correct, use %I64d for signed 64-bit and %I64u for unsigned.

 * retrieve __int64 values from strings?  I assume there is no
   strtoll?

 No, but MSVC7 has a __int64 __cdecl _strtoi64(const char *str, char
 **endptr, int base);

Thanks for the info.  Is it OK to just require MSVC7, or should we
write a compatibility function for earlier versions?  The nice thing
about _strtoi64 is that its interface is compatible with strtoll,
which means one can #define str_to_wgint to strtol, strtoll, or
_strtoi64, as appropriate for the platform.

One more question: how does one spell 64-bit constants in MSVC?
google seems to suggest nnnI64; how portable is that?


Re: Windows and long long

2005-02-20 Thread Hrvoje Niksic
Gisle Vanem [EMAIL PROTECTED] writes:

 Hrvoje Niksic wrote:

 Thanks for the info.  Is it OK to just require MSVC7, or should we
 write a compatibility function for earlier versions?

 Write a compatible function IMHO. A lot of users (including me) still
 uses MSVC6.

OK.  I don't think we can use sscanf, though, because strtol(l)
supports (and Wget uses) overflow detection.

 One more question: how does one spell 64-bit constants in MSVC?
 google seems to suggest nnnI64; how portable is that?

 That can be expressed with:

 #if defined(_MSC_VER) || defined(__WATCOMC__)
   #define S64_SUFFIX(x)  (x##i64)
   #define U64_SUFFIX(x)  (x##Ui64)
 #else
   #define S64_SUFFIX(x)  (x##LL)
   #define U64_SUFFIX(x)  (x##ULL)
 #endif

That won't work with old compilers which Wget still (unless Mauro has
decreed otherwise) supports.  Fortunately, I need 64-bit constants in
only one place, which is now correctly ifdeffed.