Long long printing problems with newlib 1.16.0?

Dave Korn dave.korn@artimi.com
Thu Jan 3 20:08:00 GMT 2008


On 03 January 2008 17:16, Franzi Edo. wrote:

> Hi,
> I tried to use printf in a cross 68k machine. The print "unsigned long
> long" seems not to work.
> 
> unsigned long long a = 9888994872930475ull;
> 
> printf("%llu", a)
> -> gives as a result 2302461 on my cross target 68k

  Which, as you might expect, is the high 32 bits of 9888994872930475.

> -> gives as a result 9888994872930475 on my host machine OSX
> 
> How do I have to configure newlib to correctly support long long int
> on embedded targets? Whit the previous version of the newlib 1.15.0,
> the flag "--enable-newlib-io-long-long" was enough.
> 
> Any advises?

  Just to check, do you know that configure supports a --help option?  However
the help from the top-level configure isn't necessarily useful.  Some
configure scripts support an option "--help=recursive", or if that doesn't
work, it's ok to run the configure script one level lower down in the newlib
directory itself, in order to see the help output.

> ../../../GCC/gcc-$GCC_VER/configure --target=$target --prefix=$prefix
> --enable-languages=c --with-newlib --enable-newlib-io-long-long --with-
> gnu-as --with-gnu-ld

  Right, just have to check here: you are actually using a combined tree build
here, and didn't just have a thinko and forget to give the same arguments when
configuring newlib as a separate build?

  Assuming it's not a trivial problem like that, adding
--enable-newlib-io-c99-formats might force it, but as far as I can see
--enable-newlib-io-long-long ought to be enough.  It would be informative if
you could patch the file newlib/libc/stdio/vfprintf.c and we'll see what's
going on: if you find this bit around line #156


--------------------------<!snip!>--------------------------
#define _NO_LONGLONG
#if defined _WANT_IO_LONG_LONG \
	&& (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
# undef _NO_LONGLONG
#endif
--------------------------<!snip!>--------------------------

and add some #warnings like so:

--------------------------<!snip!>--------------------------
#define _NO_LONGLONG
#if defined _WANT_IO_LONG_LONG \
	&& (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
# undef _NO_LONGLONG
#warning No long long support
#if defined _WANT_IO_LONG_LONG
#warning Because not GNU C nor STDC
#else
#warning Because not configured for long long
#endif
#endif
--------------------------<!snip!>--------------------------

and maybe find this bit at line 757 or so in int _DEFUN(_VFPRINTF_R, (data,
fp, fmt0, ap):

--------------------------<!snip!>--------------------------
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
			if (*fmt == 'l') {
				fmt++;
				flags |= QUADINT;
			} else
#endif
--------------------------<!snip!>--------------------------

and add a #else

--------------------------<!snip!>--------------------------
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
			if (*fmt == 'l') {
				fmt++;
				flags |= QUADINT;
			} else
#else
#ifndef _WANT_IO_C99_FORMATS
#warning No c99 i/o formats requested
#endif
#endif
--------------------------<!snip!>--------------------------

then we'll have some better idea why it's not working when you recompile and
we see what's not being defined properly.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Newlib mailing list