🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4809

Re: CLOCKS_PER_SEC not defined

#4809
From: Nick Maclaren
Date: Fri, 16 Feb 1996 10:14
37 lines
1711 bytes
In article <ramin.1174728902A@news.gsfc.nasa.gov>, ramin@twinkie.gsfc.nasa.gov (Ramin Sina) writes:
|> Hello everyone,
|> 
|> I am using a supposedly ansi c program in which I write
|> 
|> #include <time.h>
|> 
|> #if defined(__STDC__) && !defined(CLOCKS_PER_SEC)
|> #error "CLOCKS_PER_SEC is not defined on this stupid compiler"
|> #endif
|> 
|> I get the error that CLOCKS_PER_SEC is not defined. I had thought that it
|> was defined in standard C in the time.h header. I need CLOCKS_PER_SEC to
|> time how long it takes for the program to run. Can anybody suggest how I can
|> fix this problem.

You are probably using SunOS!  I recommend code like the following
to fix up the problem.  Note that this will work on K&R C as well,
which is why it doesn't use #elif.  If you hit a compiler without
either CLOCKS_PER_SEC or CLK_TCK and other than 1000000 a second,
you are in trouble :-(

#ifndef CLOCKS_PER_SEC
#ifdef CLK_TCK
#define CLOCKS_PER_SEC CLK_TCK   /* Some systems still use this older form */
#endif
#endif
#ifndef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC 1000000   /* For non-ANSI systems, like SunOS! */
#endif


Nick Maclaren,
University of Cambridge Computer Laboratory,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679
Technical Details
Message-ID: <4g1ldo$i2b@lyra.csx.cam.ac.uk>
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
References: <ramin.1174728902A@news.gsfc.nasa.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lyra.csx.cam.ac.uk!nmm1
From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.std.c
Subject: Re: CLOCKS_PER_SEC not defined
Date: 16 Feb 1996 10:14:16 GMT
Organization: University of Cambridge, England
Message-ID: <4g1ldo$i2b@lyra.csx.cam.ac.uk>
References: <ramin.1174728902A@news.gsfc.nasa.gov>
NNTP-Posting-Host: ursa.cus.cam.ac.uk