www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/06/04:48:14

Xref: news2.mv.net comp.os.msdos.djgpp:4656
From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why doesnt this work!
Date: Wed, 05 Jun 1996 19:33:46 -0700
Organization: Alcyone Systems
Lines: 26
Message-ID: <31B6438A.4BEC9AE0@alcyone.com>
References: <4p3uct$h50 AT raffles DOT technet DOT sg> <4p3vv1$ocg AT news DOT cea DOT fr>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Eric NICOLAS wrote:

> Yes, I think you're wrong. The problem is that (end-start)/CLK_TCK is
> an integer value, where printf is waiting for a float value. You
> can try :
>         printf("The time was: %f\n", 1.*(end - start) / CLK_TCK);
> that should work.

There's no need to introduce a superfluous multiply.  Try a cast to a float
instead.

The original problem was two-fold.  First, the expression was of integral
type, not of floating-point type.  You need an explicit cast to float in there
to coerce it so that the computation is done in floating point.

The second problem was that of using printf in this manner.  The compiler has
no way of knowing that the first parameter to the variable argument list is
_supposed to be_ a float (it has the %f format specifier), when in actuality
it is of integral type.  This is a Bad Thing.

-- 
Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com
San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_

- Raw text -


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