[PATCH]: Enable positional arguments by default for Cygwin's printf

Nicholas Wourms nwourms@netscape.net
Wed Nov 19 15:49:00 GMT 2003

Hi All,

I posted a message to the Cygwin developers list asking if anyone had an
objection to doing this.  Since noone expressed any, I think we should enable
this since it will enhance our printf and improve compatibility w.r.t. sources
from other *nixes.  As mentioned before in my message to the devel list, it
also is specifed as a standard for Unix98.  However, I was required to fix what
appeared to be a typo in vfprintf.c for %n when the argument is a long long.
The pointer quad_ptr_t was already defined with the *, so the extra * after
quad_ptr_t is extraneous and causes the CPP concatination to fail when
positional args are enabled.

In any event, after fixing that up, I sucessfully compiled the Cygwin dll.  I
ran a few tests, including some portions of the glibc printf test.  The results
were as expected and confirmed that positional arguments were functioning
properly.  For reference, I have attached a small, working testcase to
demonstrate postional arguments and prove they work on Cygwin.  Also attached
is the patch adding -DWANT_IO_POS_ARGS to Cygwin's line in configure.host and
fixing the aforementioned problem in vfprintf.c.

Of course, this is up to Chris or Corinna to approve, so I await their

-------------- next part --------------
Index: newlib/configure.host
RCS file: /cvs/src/src/newlib/configure.host,v
retrieving revision 1.55
diff -u -3 -p -r1.55 configure.host
--- newlib/configure.host	7 Nov 2003 23:47:04 -0000	1.55
+++ newlib/configure.host	18 Nov 2003 17:57:44 -0000
@@ -432,7 +432,7 @@ case "${host}" in
 	test -z "$cygwin_srcdir" && cygwin_srcdir=`cd ${srcdir}/../winsup/cygwin; pwd`
 	export cygwin_srcdir
 # RTEMS supplies its own versions of some routines:
Index: newlib/libc/stdio/vfprintf.c
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.22
diff -u -3 -p -r1.22 vfprintf.c
--- newlib/libc/stdio/vfprintf.c	7 Nov 2003 16:01:17 -0000	1.22
+++ newlib/libc/stdio/vfprintf.c	18 Nov 2003 17:57:45 -0000
@@ -869,7 +869,7 @@ reswitch:	switch (ch) {
 		case 'n':
 #ifndef _NO_LONGLONG
 			if (flags & QUADINT)
-				*GET_ARG(N, ap, quad_ptr_t *) = ret;
+				*GET_ARG(N, ap, quad_ptr_t) = ret;
 			if (flags & LONGINT)
-------------- next part --------------
 * Simple *printf positional argument test.
 * Returns 0 on success and 1 on failure.
 * Compile: gcc -o testpos testpos.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main(void) {
  char buffer[256];

  sprintf (buffer, "%2$d %3$d %1$d", 1, 2, 3);
  if (strcmp ("2 3 1", buffer) == 0) {
    printf("Great, positional arguments seem to work!\r\n");
  printf("Uh-oh, positional arguments are broken!\r\n");

More information about the Newlib mailing list