Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #58524

Re: More trouble with strtoul

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: More trouble with strtoul
Date 2015-03-20 10:56 -0700
Organization None to speak of
Message-ID <871tkjy2l2.fsf@kst-u.example.com> (permalink)
References <meghap$4dk$1@speranza.aioe.org> <87egojy7rj.fsf@kst-u.example.com> <mehi8h$2ss$1@speranza.aioe.org>

Show all headers | View raw


jacob navia <jacob@jacob.remcomp.fr> writes:
> d:\lcc\libc\test>gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=c:/tdm-gcc-64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
> Target: x86_64-w64-mingw32
> Configured with: ../../../src/gcc-4.8.1/configure
> --build=x86_64-w64-mingw32 --enable-targets=all --enable-lan
> guages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp
> --enable-lto --enable-graphite --enable-cxx-flags=-
> DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix
> --enable-version-specific-runtime-libs --en
> able-fully-dynamic-string --enable-libstdcxx-threads
> --enable-libstdcxx-time --with-gnu-ld --disable-werror --
> disable-nls --disable-win32-registry --prefix=/mingw64tdm
> --with-local-prefix=/mingw64tdm --with-pkgversion=td
> m64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
> Thread model: posix
> gcc version 4.8.1 (tdm64-2)

Since you're using MinGW, I believe the strtol implementation is
provided by Microsoft's runtime library, not by either gcc or glibc.  It
could be a bug in Microsoft's library, in MinGW's integration of gcc
with the library (I know it has problems with long double), or in your
test program.  I have my suspicions, but there's no point in
speculating.

I suggest trying my test program (see below) with the gcc you'reusing,
with MinGW, and with Microsoft's implementation.

If you have problems with "-4294967296" with 32-bit unsigned long, it's
likely you'd have similar problems with "-18446744073709551616" with
64-bit long.  Here's an updated test program that allows for both
possibilities.  With gcc, compiling with "-m32" (if supported) gives you
32-bit long.

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
int main(void) {
    printf("ULONG_MAX = %lu (0x%lx)\n", ULONG_MAX, ULONG_MAX);

    errno = 0;
#if ULONG_MAX == 4294967295U
    unsigned long result = strtoul("-4294967296", NULL, 0);
#elif ULONG_MAX == 18446744073709551615U
    unsigned long result = strtoul("-18446744073709551616", NULL, 0);
#else
    #error "Unexpected value for ULONG_MAX"
#endif

    printf("result = %lu (0x%lx), errno = %d",
           result, result, errno);
    if (errno == ERANGE) {
        printf(" (ERANGE)");
    }
    putchar('\n');
}

On my system, with "-m32", I get:

    ULONG_MAX = 4294967295 (0xffffffff)
    result = 4294967295 (0xffffffff), errno = 34 (ERANGE)

Without "-m32", I get:

    ULONG_MAX = 18446744073709551615 (0xffffffffffffffff)
    result = 18446744073709551615 (0xffffffffffffffff), errno = 34 (ERANGE)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 08:13 +0100
  Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 07:31 +0000
  Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 03:36 -0500
    Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 08:42 +0000
    Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 10:12 +0100
      Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 10:16 +0000
        Re: More trouble with strtoul: BUG in MSVC jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 11:49 +0100
      Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 05:54 -0500
      Re: More trouble with strtoul Barry Schwarz <schwarzb@dqel.com> - 2015-03-20 08:16 -0700
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 16:31 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 08:48 -0700
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 16:51 +0100
          Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 09:21 -0700
            Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 17:53 +0100
        Re: More trouble with strtoul glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-20 17:23 +0000
          Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 18:25 +0100
          Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 10:35 -0700
            Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:52 +1300
              Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 13:41 -0700
      Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:45 +1300
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:47 +1300
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 21:16 +0100
          Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:33 +1300
      Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 20:05 +0000
      Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-20 21:55 +0100
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 11:13 +1300
          Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-20 23:41 +0100
            Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 16:27 -0700
              Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-21 01:47 +0100
          Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-21 02:03 +0000
            Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 15:13 +1300
              Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-21 03:22 +0100
              Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-21 02:25 +0000
  Re: More trouble with strtoul Lőrinczy Zsigmond <zsiga@nospam.for.me> - 2015-03-20 10:11 +0100
    Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 06:13 -0500
  Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 09:05 -0700
    Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 17:35 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 10:56 -0700
        Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 15:31 -0500
  Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 18:28 +0100
    Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:01 +1300
      Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 21:12 +0100
        Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 20:21 +0000
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:36 +1300
        Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 15:47 -0500
          Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 21:20 +0000
            Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-21 00:24 -0500
          Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 23:04 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 13:41 -0700
  Re: More trouble with strtoul raltbos@xs4all.nl (Richard Bos) - 2015-03-21 22:49 +0000
    Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-21 16:17 -0700
      Re: More trouble with strtoul Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 12:01 -0700

csiph-web