mktime and time_t in dinkum libs

mktime() returns a “time_t” value, which is unsigned in the Dinkum libs.
However, doc says that mktime() returns -1 in case of error.
Hence, I have to typecast the return value of mktime(), which is not good
programming style…
Markus

Markus Loffler <loffler@ces.clemson.edu> wrote:

mktime() returns a “time_t” value, which is unsigned in the Dinkum libs.
However, doc says that mktime() returns -1 in case of error.
Hence, I have to typecast the return value of mktime(), which is not good
programming style…

Oddly enough, in _The C Programming Language, second edition, (by Kernighan
and Ritchie), page 256, for mktime() it says:

mktime returns the calendar time or -1 iif it cannot be represented.

I’m not sure that K&R is still THE standard for the C language, but
Dinkum isn’t coming from left field with this one.

-David

QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:

Markus Loffler <> loffler@ces.clemson.edu> > wrote:
mktime() returns a “time_t” value, which is unsigned in the Dinkum libs.
However, doc says that mktime() returns -1 in case of error.
Hence, I have to typecast the return value of mktime(), which is not good
programming style…

You shouldn’t typecast the return value of mktime() – you should
typecast the -1. That’s probably what you meant anyway, isn’t it:

if ( mktime(…) == (time_t)(-1) )… // Good
if ( (int)mktime(…) == -1 )… // Bad


If you don’t like typecasting in general, complain to the C standard
committee…


Oddly enough, in _The C Programming Language, second edition, (by Kernighan
and Ritchie), page 256, for mktime() it says:

mktime returns the calendar time or -1 iif it cannot be represented.

I’m not sure that K&R is still THE standard for the C language, but
Dinkum isn’t coming from left field with this one.

K&R hasn’t been THE standard for the C language since 1989, Dave… :slight_smile:

K&R is not quite accurate here. Since time_t is only required to be an
arithmetic type (which K&R does say on page 255), it doesn’t have to be
capable of representing the value -1. Requiring that mktime() must be
able to return -1 would be a silly way of saying that time_t is not
allowed to be an unsigned type. The C standard doesn’t make that
mistake – it says that mktime() returns (time_t)(-1) on error.


\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Wojtek Lerch <wojtek@qnx.com> wrote:

David Gibbs <> dagibbs@qnx.com> > wrote:

I’m not sure that K&R is still THE standard for the C language, but
Dinkum isn’t coming from left field with this one.

K&R hasn’t been THE standard for the C language since 1989, Dave… > :slight_smile:

sigh I feel old.

-David

QNX Training Services
dagibbs@qnx.com

Me too. Wanna see my S-100 Tarbell cassette interface board?

-Warren “IMSAI 8080” Peece



“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9hvm67$d04$1@nntp.qnx.com
| Wojtek Lerch <wojtek@qnx.com> wrote:
| > David Gibbs <dagibbs@qnx.com> wrote:
|
| >> I’m not sure that K&R is still THE standard for the C language, but
| >> Dinkum isn’t coming from left field with this one.
|
| > K&R hasn’t been THE standard for the C language since 1989, Dave… :slight_smile:
|
| sigh I feel old.
|

-David
QNX Training Services
dagibbs@qnx.com