From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b1850e397df49d95 X-Google-Attributes: gid103376,public From: "Jerry van Dijk" Subject: Re: How to convert an Fixed_Point to to an Integer ? Date: 1996/12/24 Message-ID: <01bbf179$0c4361e0$9b2d5c8b@jerryware>#1/1 X-Deja-AN: 205734162 references: <01bbf058$cbdbf980$LocalHost@jerryware> <1996Dec23.072835.1@eisner> organization: *JerryWare HQ*, Haarlem, Holland newsgroups: comp.lang.ada Date: 1996-12-24T00:00:00+00:00 List-Id: Robert Dewar wrote in article ... > 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.