delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/10/14/13:56:53

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <051901c3927c$b7d0f2b0$cd8a9dc0@uk.aonix.com>
From: "Cliff Hones" <cliff AT aonix DOT co DOT uk>
To: "Alex Vinokur" <alexvn AT connect DOT to>, <cygwin AT cygwin DOT com>
References: <bmhbv6$fu1$1 AT sea DOT gmane DOT org>
Subject: Re: clock_t & return -1
Date: Tue, 14 Oct 2003 18:58:04 +0100
Organization: Aonix Europe
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019