From: "Jerry van Dijk" <jvandyk@ibm.net>
Subject: Re: How to convert an Fixed_Point to to an Integer ?
Date: 1996/12/24
Date: 1996-12-24T00:00:00+00:00 [thread overview]
Message-ID: <01bbf179$0c4361e0$9b2d5c8b@jerryware> (raw)
In-Reply-To: dewar.851351937@merv
Robert Dewar <dewar@merv.cs.nyu.edu> wrote in article
<dewar.851351937@merv>...
> Well obviously Time is really a private type, so you are talking about
doing
> something very implementation dependent and nasty here.
Hmmmm, I don't know. The idea behind encapsulation is protecting the client
code
against changes in implementation, not preventing anyone to assign the
number of
seconds since the epoch to an Integer :-)
The real problem is that there is no conversion operation offered for the
type.
So I solved it by putting these conversion operation in a child of
Ada.Calender:
package Ada.Calendar.Posix is
type Time_T is mod 2 ** Integer'Size;
function Clock return Time_T;
function To_Time (Date : Time_T) return Ada.Calendar.Time;
function To_Time_T (Date : Ada.Calendar.time) return Time_T;
end Ada.Calendar.Posix;
package body Ada.Calendar.Posix is
function Clock return Time_T is
begin
return To_Time_T (Ada.Calendar.Clock);
end Clock;
function To_Time (Date : Time_T) return Ada.Calendar.Time is
begin
return Ada.Calendar.Time (Date);
end To_Time;
function To_Time_T (Date : Ada.Calendar.Time) return Time_T is
begin
return Time_T (Date);
end To_Time_T;
end Ada.Calendar.Posix;
> You will have to use Unchecked conversion to a type that has exactly the
> same range and delta as duration, you could use duration itself for this
> purpose.
Yes, but talking about messy...
> But really, you should ask yourself if you want to do this. The resulting
> code is highly non-portable and conceptually wrong.
Well, I am writing a more-or-less POSIX-like binding for use with
GNAT/DJGPP.
And that code is inherently non-portable anyway. On the other hand, it does
wonders for the portability of my code between GNAT/Linux and GNAT/DOS :-)
Thanks everyone, for the replies.
Jerry.
P.S. Although the newsfeed on jvdsys.nextjk.stuyts.nl is down, I can still
be
reached there.
next prev parent reply other threads:[~1996-12-24 0:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-12-22 0:00 How to convert an Fixed_Point to to an Integer ? Jerry van Dijk
1996-12-23 0:00 ` Larry Kilgallen
1996-12-23 0:00 ` Robert Dewar
1996-12-24 0:00 ` Jerry van Dijk [this message]
1996-12-24 0:00 ` Robert Dewar
1996-12-24 0:00 ` Norman H. Cohen
1996-12-24 0:00 ` Robert Dewar
1996-12-26 0:00 ` Keith Thompson
1996-12-26 0:00 ` Robert Dewar
1996-12-25 0:00 ` Jerry van Dijk
1996-12-25 0:00 ` Robert Dewar
1996-12-26 0:00 ` Norman H. Cohen
1996-12-27 0:00 ` Jerry van Dijk
1996-12-27 0:00 ` Leap seconds in Unix time (was: Re: How to convert an Fixed_Point to to an Integer ?) Norman H. Cohen
1996-12-30 0:00 ` How to convert an Fixed_Point to to an Integer ? Mike Young
1996-12-30 0:00 ` Michael F Brenner
1996-12-30 0:00 ` 2000 is a leap year (was: How to convert an Fixed_Point to to an Inte) Larry Kilgallen
1996-12-31 0:00 ` How to convert an Fixed_Point to to an Integer ? Keith Thompson
1997-01-02 0:00 ` 2000 is a leap year (was: How to convert an Fixed_Point to to an Inte) Mike Paley
1996-12-23 0:00 ` How to convert an Fixed_Point to to an Integer ? Jerry van Dijk
1996-12-23 0:00 ` Eric Miller
1996-12-30 0:00 ` Dave Barnes
1996-12-30 0:00 ` Steve Jones - JON
1996-12-30 0:00 ` Steve Jones - JON
1996-12-30 0:00 ` Jacques Rouillard
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox