Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: More trouble with strtoul Date: Fri, 20 Mar 2015 10:56:57 -0700 Organization: None to speak of Lines: 75 Message-ID: <871tkjy2l2.fsf@kst-u.example.com> References: <87egojy7rj.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="31696"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WRQIYXIeRcEr/i9AOcTt7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:LHRTdkS1tv5HVKhNVqu/CL4ZWbo= sha1:RofxswpXrmA/rYddzXhU5TVmWNM= Xref: csiph.com comp.lang.c:58524 jacob navia 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 #include #include #include 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 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"