Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-11

question about FpTimes in BaseUnix package

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bruce Bauman

I am using the FpTimes function from the BaseUnix package. The documentation says it returns -1 on an error, otherwise the number of clock ticks since boot time. However, the return type of this function is TClock, which is unsigned.

This, if I say:

X := BaseUnix.FpTimes(T);

if (X -1) then ...

I get a compiler-time warning (range check error while evaluating constants).

Should the return type not be unsigned? Is checking the result against -1 OK?

-- Bruce
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Jonas Maebe
to Bruce Bauman
Bruce Bauman wrote
I am using the FpTimes function from the BaseUnix package. The documentation says it returns -1 on an error, otherwise the number of clock ticks since boot time. However, the return type of this function is TClock, which is unsigned.

From "man 3 times":

If an
error occurs, times() returns the value ((clock_t)-1), and sets errno to indicate the error.

So check against TClock(-1).

Jonas

Henry Vermaak
to Rainer Stratmann

2009/11/17 Rainer Stratmann :

Show quoted text 7 lines
Am Tuesday 17 November 2009 19:34:19 schrieb Bruce Bauman: > I am using the FpTimes function from the BaseUnix package. The > documentation says it returns -1 on an error, otherwise the number of > clock ticks since boot time. What does clock ticks exactly mean? I am searching for an equivalent to getticks in windows.

If you want to measure uptime, then you need to use sysinfo. The resolution is seconds, though.

Henry

Luca Olivetti
to Rainer Stratmann: What does clock ticks exactly mean? I am searching for an equivalent to getticks in…

En/na Rainer Stratmann ha escrit:

Show quoted text 7 lines
Am Tuesday 17 November 2009 19:34:19 schrieb Bruce Bauman: > I am using the FpTimes function from the BaseUnix package. The > documentation says it returns -1 on an error, otherwise the number of > clock ticks since boot time. What does clock ticks exactly mean? I am searching for an equivalent to getticks in windows.

There isn't one.
Lazarus defines a compatibility GetTickCount as such:

Result := DWord(Trunc(Now * 24 * 60 * 60 * 1000));

it's not the same as windows' GetTickCount but it can be used if you just want to calculate elapsed time (provided the clock doesn't jump back/forward).

Bye

Luca