bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] strptime: silence gcc warnings


From: Bruno Haible
Subject: Re: [PATCH 2/2] strptime: silence gcc warnings
Date: Thu, 12 Jan 2012 04:31:17 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Eric Blake wrote:
> @@ -683,7 +684,9 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt 
> LOCALE_PARAM)
>                ++rp;
>              if (*rp != '+' && *rp != '-')
>                return NULL;
> +#if defined _LIBC || HAVE_TM_GMTOFF
>              neg = *rp++ == '-';
> +#endif
>              n = 0;
>              while (n < 4 && *rp >= '0' && *rp <= '9')
>                {

Here you need to pull the side effect of the statement outside the #if.

gcc would have done this optimization correctly. If you do it by hand,
you have a risk of introducing bugs. That's why -Wunused-but-set-variable
is not a good warning to enable all the time: It's the compiler's job
to eliminate unused variables.

I don't want a compiler that warns about each and every optimization it
performs, because such pickiness means that I have to write code at a
lower level, with more manual micro-optimizations, than I really want to.

Imagine if gcc had a warning to signal that a loop is only performed once
(and thus the 'for/do/while' around it is not needed). It would make it
impossible to use the   do { ... } while (0)  idiom.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]