This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/6547: misleading printf '$' format
- From: "Pierre-Canalsat PETIT" <pierrecanalsat dot petit dot canalsat at canal-plus dot com>
- To: jsm28 at cam dot ac dot uk
- Cc: gcc-bugs at gcc dot gnu dot org,gcc-gnats at gcc dot gnu dot org,Joseph Myers <jsm28 at srcf dot ucam dot org>,peio at blutch dot dyndns dot org,prpetit at canal-plus dot com
- Date: Fri, 3 May 2002 16:18:13 +0200
- Subject: Re: c/6547: misleading printf '$' format
> You can't mix $ and non-$ formats in one format string; see the Single
> Unix Specification. Once a non-$ format is detected, $ operand numbers
> are no longer checked for. Note that "%." can only be the start of a
> non-$ format.
====(forgot to answer to all...)====
True.. I forgot that, thanks.
So gcc-3.0 has no misleading warning, good point
(maybe a more verbose warning should be written..).
Note v2.95.4 still has one :
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("%2$.*1$s\n", argc, *argv);
return 0;
}
This gives a "warning: unknown conversion type character '1' in format"
====(Snap)====
There is still a problem it seems on gcc v3.0.4.. :
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
printf("Usage: %1$s [-n <option 1>] [-m <option 2>]\n"
" %3$*2$c [-i <input>] [-o <output>] [-c <nb>] [-t <ms>]\n"
" %3$*2$c <file.in> <file.out>\n", *argv, strlen(*argv), ' ');
return 0;
}
This returns me a "warning: too few arguments for format".
But if you remove the second line of the format, it does compile
without warning...
--
Pierre PETIT