This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: format specifier for long long incompatible to glibc


Arno Wagner wrote:

Example:

#include <stdio.h>

void main() {
   long long i;

i = 10000000000L;

   printf("sizeof long long: %d\n", sizeof(i));
   printf("L specifier:  %12Ld\n", i);
   printf("q specifier:  %12qd\n", i);
   printf("ll specifier: %12lld\n", i);
}

gives:

sizeof long long: 8
L specifier:    1410065408
q specifier:   10000000000
ll specifier:  10000000000

Using -pedantic helps to catch this, then -std=c99 is required to accept "%lld":


$ gcc -Wall -pedantic -std=c99 fmt.c
fmt.c: In function 'main':
fmt.c:9:3: warning: ISO C does not support the '%Ld' gnu_printf format
fmt.c:9:3: warning: ISO C does not support the '%Ld' gnu_printf format
fmt.c:10:3: warning: ISO C does not support the 'q' gnu_printf length modifier
fmt.c:10:3: warning: ISO C does not support the 'q' gnu_printf length modifier


(This shows a minor gcc bug: All format warnings are printed twice, one for builtin printf, one for printf prototype)


The MinGW and MinGW-w64 compilers have a similar issue when MinGW stdio is selected:


$ cygcheck -f /usr/bin/i686-w64-mingw32-gcc
mingw64-i686-gcc-core-4.5.3-6

$ i686-w64-mingw32-gcc -ofmt -D__USE_MINGW_ANSI_STDIO -Wall -static fmt.c

$ ./fmt
sizeof long long: 8
L specifier:    1410065408
q specifier:  %12qd
ll specifier:  10000000000


I think this should be fixed, as it may really mess up things
and, to make matters worse, only shows up when the argument exceeds
the integer value limits, making it potentially hard to find.


The problem is that the gnu_printf format check from gcc assumes the behavior of glibc printf. This needs to be fixed in the compiler sources if another libc is used.


The format modifier 'L' exists to select the (12 byte) 'long double' type, for example "%Lf". This also works with Cygwin.
Using 'L' in conjunction with 'd' is (AFIAK) non-standard. Adding this to Cygwin might be rejected.



Versions:
   cygwin libc:   No idea, which package is that thing in?
                  Installed 12/2012 though, so pretty new.

The libc is "newlib" and is part of cygwin1.dll from package cygwin. See vfprintf.c at http://www.sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/stdio/?cvsroot=src

Christian


-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]