bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral


From: Bruno Haible
Subject: Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral
Date: Sun, 10 Oct 2010 23:15:34 +0200
User-agent: KMail/1.9.9

Paul Eggert wrote:
> * lib/time.in.h (struct __time_t_must_be_integral): Rewrite
> 2 * ((time_t) 1 / 2 == 0) - 1 to (time_t) 1; this suffices to
> verify that time_t cannot be floating.

I disagree that this is enough. The C standard says that a cast to floating-
point types cannot be portably used in integer constant expressions. But a
compiler is free to support this, as an extension. _If_ a compiler supports
it as an extension, then
  2 * ((time_t) 1 / 2 == 0) - 1           will evaluate to -1
  (time_t) 0.5 == 0 ? 1 : -1              will evaluate to -1
but the expression you put in:
  (time_t) 1                              will evaluate to 1

Bruno



reply via email to

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