warning: `%y' yields only last 2 digits of year

Michael Matz matzmich@cs.tu-berlin.de
Wed Mar 13 08:30:00 GMT 2002


Hi,

On Wed, 13 Mar 2002, Robert Dewar wrote:

> <<Which is still wrong since years can span more than just 1900 - 2099.
> What's wrong with using %Y in the first place?
> >>
>
> A common technique for dealing with the Y2K problem, in cases where it
> is impractical to modify data structures or databases, is to use what
> is usually called windowing.
>
> For instance an insurance company may know that it did not exist
> before 1982, so any date in the range 82-99 is 1982-1999, and any date
> in the range 00-81 is 2000-2081. This would of course be suitable only
> for policy inception dates, not for client birthdates, but for the
> inception date use, this can keep them going another 80 years, which
> may be plenty (if for example they anticipate a complete system
> rewrite before 2080).

I think we all know what windowing is, thank you.  The above still breaks
if that insurance company is existing longer than 100 years and the
"complete rewrite" didn't happen, which is far more probable than that it
exists more than 10000 years.  I.e. the above is not a solution but a hack
around the real problem, equally if they used your suggestion to have 19%y
and 20%y in different branches.  Still not a solution (maybe one to the
Y2K problem, but only by shifting it to a Y2.1K problem).

> Once again, please don't assume you know better than the applications
> programmer what the *applications* requirements are. Warnings in
> languages should be about supposing that you know enough about the
> *language* in which the application is being written to identify
> constructs that are suspicious at the language level.

Well, I think, warnings should be ultimately usefull for most users.
E.g.  those other warnings about printf() formats I think are usefull.
They would need to go away when the above principle is applied, because
it's an application of the language, not a language mean itself (i.e.
'debug("%s:%d", 42);' is prefectly legal C, but gcc can warn about this).
I'm not sure if you think this is useless.

I think most users of gcc are casual programmers, which despite us
wanting, do not know all the meanings and issues, and ISO-C(++), so it
makes sense IMHO to warn by default about constucts which are potentially
(or likely enough) harmfull.  People who do know can switch off those
annoying warnings.  If this particular case %y is harmfull/unwanted in
enough cases is something I don't want to judge.

In the other thread on this topic you wrote:
> But all this irrelevant discussion has nothing to do with the warning.
> %y is a perfectly well defined, and useful function. it is reasonable
> to assume that anyone using this function knows what it does and means
> to use it.

So, what you are trying to tell us in your priggish style is, that we
shouldn't warn about any perfectly well defined thing?  (Usefullness can't
be measured exactly and differs between users, so shouldn't be a
criterion)  Because it's reasonable to assume, that every users knows what
it does?  A strange opinion IMHO.

About the usefullness of this %y warning: I'm not sure of it.  I guess as
it was introduced and used for recompiling old sources some potentially
problematic uses of %y were discovered, where the original author did not
meant to use it.  This alone would have justified the warning.  If it
should be in -Wall I don't know.  If yes, your insurance company surely
will find out how to switch off the warning and can audit the code by
hand.


Ciao,
Michael.



More information about the Gcc mailing list