This is the mail archive of the gcc@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]

gcc bug: complaint on %c for strftime


Various versions of gcc such as gcc 3.2 complain
about strftime(,,"%c",) with the reaction

warning: `%c' yields only last 2 digits of year in some locales

This is a bug.

%c is described as: the preferred date and time representation
for the current locale. How can you give an error message for
that? What is the programmer to do? Choose a non-preferred
representation?

The docs for Wall say:
       -Wall  All  of the above `-W' options combined.  These are
              all the options which pertain to usage that we rec­
              ommend  avoiding  and  that  we  believe is easy to
              avoid, even in conjunction with macros.
so %c should be easy to avoid. I have no idea how.

But the warning is easy to avoid using silliness like

/*
 * Stop extremely silly gcc complaint on %c:
 *  warning: `%c' yields only last 2 digits of year in some locales
 */
static void
my_strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) {
        strftime(buf, len, fmt, tm);
}

[this is what I do now in util-linux, but I can hardly imagine
that this is what you hoped to achieve].

Andries


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