snprintfv 1.1 pre-release

Dave Butenhof David.Butenhof@hp.com
Thu Jul 24 19:29:00 GMT 2003


Bruce Korb wrote:

>"Joseph S. Myers" wrote:
>  
>
>>On Thu, 24 Jul 2003, Paolo Bonzini wrote:
>>    
>>
>>>* there is support for width/precision positional parameters (%NNN$s was
>>>supported in 1.0 too), like
>>>
>>>    printf ("%2$*1$s", "fubar", -10);
>>>      
>>>
>>This, of course, being an erroneous example, taking "fubar" as the width
>>and -10 as the string to be formatted.
>>    
>>
>Well, I confess I don't know what is right.  What you say, Joseph, corresponds
>to my reading of the standard.  However, in experiments with Sun's libc and
>Linux's glibc:
>
I'm not sure why this got sent to the Austin group list; and perhaps I'm 
missing some important context, but...

>>$ cat xx.c
>>#include <stdio.h>
>>
>>int
>>main( int argc, char** argv )
>>{
>>    printf( "%%2$*1$d:  ==%2$*1$d==\n", 11, 22 );
>>    printf( "%%1$*2$d:  ==%2$*1$d==\n", 11, 22 );
>>    printf( "%%*d:      ==%2$*1$d==\n", 11, 22 );
>>
Excuse me, but why are all the actual formatting strings identical? It 
appears that it's doing exactly what you told it to do. I think you must 
have INTENDED to do this:

    #include <stdio.h>
    int
    main( int argc, char** argv )
    {
        printf( "%%2$*1$d:  ==%2$*1$d==\n", 11, 22 );
        printf( "%%1$*2$d:  ==%1$*2$d==\n", 11, 22 );
        printf( "%%*d:      ==%*d==\n", 11, 22 );
        return 0;
    }

That is, on each line REPORT and USE the same formatting. Yes?

>>    return 0;
>>}
>>$ cc    -o xx xx.c 
>>$ ./xx
>>%2$*1$d:  ==         22==
>>%1$*2$d:  ==         22==
>>%*d:      ==         22==
>>$ gcc -o yy xx.c
>>$ ./yy
>>%2$*1$d:  ==         22==
>>%1$*2$d:  ==         22==
>>%*d:      ==         22==
>>    
>>
>I'm pretty sure that something has to be wrong.  What?  Can we say
>that both are in non-compliance and the results should be this?
>
>>%2$*1$d:  ==         22==
>>%1$*2$d:  ==                    11==
>>%*d:      ==         22==
>>    
>>
On Tru64, when I build and run the program you posted I get exactly what 
you report Solaris and Linux doing. But when I correct the program to do 
what it says, I get what you expect. I suspect you'll find the same 
results. (I certainly do on our ancient Solaris 2.6 system; I didn't 
bother trying on Linux.)

-- 
/--------------------[ David.Butenhof@hp.com ]--------------------\
| Hewlett-Packard Company       Tru64 UNIX & VMS Thread Architect |
|     My book: http://www.awl.com/cseng/titles/0-201-63392-2/     |
\----[ http://homepage.mac.com/dbutenhof/Threads/Threads.html ]---/




More information about the Gcc mailing list