tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: strtoll question
On Sep 14, 2014, at 9:35 PM, Emmanuel Dreyfus <manu%netbsd.org@localhost> wrote:
> Hello
>
> Consider the program below and its output. Am I using strtoll() wrongly,
> or is this a bug? (this is netbsd-7 branch)
>
> $ cat /tmp/x.c
> #include <stdio.h>
> #include <errno.h>
> #include <sys/types.h>
>
> int
> main(void)
> {
> const char *ptr = "999999999999999";
> char *endp;
> long long int res;
>
> errno = 0;
> res = strtoll(ptr, &endp, 0);
> printf("errno = %d\n", errno);
> printf("*endp = 0x%02x\n", *endp);
> printf("str %s\n", ptr);
> printf("num %lld\n", res);
>
> return 0;
> }
>
> $ cc -o /tmp/x /tmp/x.c
> $ /tmp/x
> errno = 0
> *endp = 0x00
> str 999999999999999
> num -1530494977
No. You have no prototype for strtoll in scope.
(gdb) print (int) 999999999999999
$1 = -1530494977
You are missing #include <stdlib.h>
-Wall is your friend.
a.c:14:8: warning: implicit declaration of function 'strtoll'
[-Wimplicit-function-declaration]
res = strtoll(ptr, &endp, 0);
Home |
Main Index |
Thread Index |
Old Index