Re: Long long int's and sprintf

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 06/16/01


Mike Stilson wrote:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> $ gcc -std=c99 -Wall -o test test.c
> test.c: In function `main':
> test.c:10: warning: implicit declaration of function `strtoull'
> test.c:12: warning: unsigned int format, different type arg (arg 3)
> test.c:12: warning: long int format, different type arg (arg 6)
> test.c:12: warning: long unsigned int format, different type arg (arg 7)
> test.c:12: warning: unsigned int format, different type arg (arg 8)
> test.c:12: warning: int format, different type arg (arg 9)

I wanted to see where those warnings came from so here's the details from
my system:

$rpm -qf /usr/include/stdlib.h
glibc-devel-2.2-12

From /usr/include/stdlib.h:

#if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_MISC)
/* These functions will part of the standard C library in ISO C99.  */

/* Convert a string to a quadword integer.  */
__extension__
extern long long int strtoll (__const char *__restrict __nptr,
                              char **__restrict __endptr, int __base)
__THROW;
/* Convert a string to an unsigned quadword integer.  */
__extension__
extern unsigned long long int strtoull (__const char *__restrict __nptr,
                                        char **__restrict __endptr, int
__base)
     __THROW;
#endif /* ISO C99 or GCC and use MISC.  */

So in order for it to work, it would appear that you need to add a
#define for __USE_ISOC99 or for both __GNUC__ and __USE_MISC before the
#include <stdlib.h>.  Note that you can also use strtouq() which is an
older BSD version and is functionally identical to strtoull() (I would
recommend strtoull() over strtouq() but you may be on an older non C99
compiler which does have support for strtouq() in which case you can
either use that directly or create a macro for strtoull()).

Regards, Peter

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST