This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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: 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



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