-Wformat cannot use const struct fields as format strings on purpose?
Basin Ilya
basinilya@gmail.com
Tue Feb 21 12:07:00 GMT 2017
Hi.
Here's a small piece of code:
static struct {
const char fmt[10];
} const x = { "%d\n" };
static const char * const fmt = "%d\n";
printf(fmt, 1);
printf(x.fmt, 1);
The second `printf` produces a warning:
test.c:105:10: warning: format string is not a string literal
[-Wformat-nonliteral]
printf(x.fmt, 1);
^~~~~
>From my point of view both format strings are identical. Why can't gcc
deduce the format string in the second case?
More information about the Gcc-help
mailing list