Subject: Re: clock_t & return -1
From: "Cliff Hones" <[email-masked]>
To: "Alex Vinokur" <[email-masked]>, <[email-masked]>
Date: Tue, 14 Oct 2003 18:58:04 +0100

Alex Vinokur wrote:
>...
> ------ Compilation ------
> 
> $ gcc -W -Wall t.c
> 
> t.c: In function `main':
> t.c:4: warning: comparison between signed and unsigned
> 
> -------------------------
> 
> So, clock() is unsigned and never returns -1 (?!)

You can find the definition of the type clock_t in the relevant
header.  (It comes from _CLOCK_T_ in machine/types.h and is
unsigned long.)  So yes, technically, clock() cannot return -1.
However, it is almost certain that the intention of the man page
is to indicate that on error it returns the same bit pattern
as (signed) -1, i.e. 0xfffffff or equivalently (clock_t)(-1).

> If one must write
>   ----------------------------------
>   if (!(clock () == (clock_t)(-1)));
>   ----------------------------------
>   I think it is worth noting that in the manual.

To be pedantic, and avoid the warning, one should write the test in
this way, but the code generated will be identical, so if you don't
mind the warning there is no need.

-- Cliff

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/