Re: __atoi64 not working correctly

From: Chris Croughton (chris_at_keristor.net)
Date: 01/22/05


Date: Sat, 22 Jan 2005 08:42:23 +0000

On Fri, 21 Jan 2005 23:09:27 -0600, Jack Klein
   <jackklein@spamcop.net> wrote:

> <off-topic>
>
> mingw is a "typical" gcc distribution, as is available for many
> platforms. It provides a tools like compiler and linker, and headers,
> but no library. It uses the platform's standard run-time library, in
> this case Microsoft's MSVC something or other DLL.

Aha! I knew there must be something different...

> The *printf() implementation in Microsoft's C library merely ignores
> the first 'l' in an "%lld" or other "%ll" conversion specifier, and
> treats the argument as a long, not a 32-bit value.

Why am I not surprised?

> So if you want real long long support under Windows, you need an
> implementation that provides its own library and supports it. These
> include lcc-win32, Pelles C, and probably the gcc implementation that
> runs under Cygwin, but I don't know this last one for sure.

I can say for sure (and did in an earlier message) -- it works fine. It
still isn't 100% compliant, though, as I recall it doesn't support %a or
the v (maxint) length modifier for integers. And some of the new macros
are missing from header files.

> </off-topic>

As someone else said recently, this means that in practice what real C
programmers have to work to is the C89/90 standard, we can be pretty
sure in most cases that compilers will support that (there are a few
unfortunate programmers who still have to support things without
function prototypes). The C99 standard is largely irrelevant from the
point of view of writing portable code, and will be until the majority
of the C compilers available are C99 compliant (modulo bugs, of course).

For instance, I want to determine the 'best' floating point type for my
application (enough significant digits with the least storage to do
that) in the
preprocessor. Simple, right? Something like

  #include <float.h>
  #if FLT_MANT_DIG >= 10
    typedef float my_float;
  #if DBL_MANT_DIG >= 10
    typedef double my_float;
  #if LDBL_MANT_DIG >= 10
    typedef long double my_float;
  #else
  # error No useful floating type!
  #endif

Wrong! It's fine for C99, where the values are required to be constant
integer expressions, but C89 says:

   Of the values in the <float.h> header, FLT_RADIX shall be a constant
   expression suitable for use in #if preprocessing directives; all
   other values need not be constant expressions. All except FLT_RADIX
   and FLT_ROUNDS have separate names for all three floating-point
   types. The floating-point model representation is provided for all
   values except FLT_ROUNDS .

(para 2.2.4.1). So the only way to test them is to have a program which
includes float.h and then prints out a header file containing
appropriate definitions (for that and other reasons I have such a
program which calculates a load of stuff about the environment -- like
the number of bits in integer types -- and outputs a header file with
the information because things like sizeof aren't allowed in
preprocessor tests).

Chris C



Relevant Pages

  • Re: GCC
    ... The header names changed explicitly to ... The Standard says that the standard ... that did not put iostream into the std namespace. ... and compilers change along with them. ...
    (Debian-User)
  • Re: Fixed sized datatypes.
    ... standard header. ... now, quite a few compilers supply this header already, and it works ... standard conforming except for the 64 bit integer types. ...
    (comp.lang.cpp)
  • Re: Automatically generate variables
    ... Must be C by your definition since crapit might possibly be a header that makes it C. ... I knew it was *the* windows windows.h header because the ... Given certain assumptions the C code was valid C code, however from what I remember it certainly was not a C program solving the problem since it not only relied on non-C APIs but also relied on external programs that in general are *not* installed on machine. ... You, on the other hand, just said that it might be C even if it goes beyond what the standard defined and gave no outer limit on what could be considered C. ...
    (comp.lang.c)
  • Re: Automatically generate variables
    ... Must be C by your definition since crapit might possibly be a header that makes it C. ... I knew it was *the* windows windows.h header because the ... if the question was "how much of the program is standard C?" ... that it's just as non-standard as my version. ...
    (comp.lang.c)
  • Re: Non-English Validation Expression for email address?
    ... The Internet Engineering Task Force has published three crucial documents for the standardisation of email address headers that include symbols outside the ASCII character set. ... This means that soon you'll be able to use Chinese characters, French accents, and German umlauts in email addresses as well as just in the body of the message. ... They say there would need to be an "upgrade mania" if the Unicode standard UTF-8 is to replace the American Standard Code for Information Interchange currently used as the general email language. ... A new header field will be added as a sort of "emergency parachute" to ensure that UTF-8 emails have a soft landing if they are thrown out before reaching the recipient by systems that have not been upgraded. ...
    (microsoft.public.dotnet.framework.aspnet)