Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - strtoul problem
1.c: #include <stdio.h> #include <stdlib.h> #include <errno.h> int main(int argc, char *argv[]) { unsigned long number = strtoul(argv[1], 0, 10); if (errno) { perror("Incorrect integer value"); return 1; } printf("number = %lu\n", number); return 0; } dmc 1.c & 1 abc number = 0 Function strtoul doesn't set errno if the conversion can not be performed. David Feb 15 2004
This is the correct behaviour according to the standard. (There is an erratum in the description of the function in my C book) David "David Grimes" <dgrimes friberg.us> wrote in message news:c0p42c$2vfh$1 digitaldaemon.com...1.c: #include <stdio.h> #include <stdlib.h> #include <errno.h> int main(int argc, char *argv[]) { unsigned long number = strtoul(argv[1], 0, 10); if (errno) { perror("Incorrect integer value"); return 1; } printf("number = %lu\n", number); return 0; } dmc 1.c & 1 abc number = 0 Function strtoul doesn't set errno if the conversion can not be performed. David Feb 17 2004
|