From: Dale Stanbrough <dale@goanna.cs.rmit.edu.au>
Subject: Re: Flags in Ada?
Date: 26 Oct 1994 00:36:04 GMT
Date: 1994-10-26T00:36:04+00:00 [thread overview]
Message-ID: <38k89k$kfk@goanna.cs.rmit.oz.au> (raw)
In-Reply-To: SPIEGEL.94Oct25113657@berlin.bruessel.informatik.uni-stuttgart.de
In article <SPIEGEL.94Oct25113657@berlin.bruessel.informatik.uni-stuttgart.de>
Andre Spiegel, spiegel@bruessel.informatik.uni-stuttgart.de writes:
>I am trying to use UNIX system calls from Ada, which has been working
>fine so far, i.e. the `translation' into Ada looks rather neat and
>secure (enumeration types with representation clauses for C #define'd
>constants, etc.), but how would I go about representing *flags* --
>i.e. words, in which the individual bits have names, and can be set,
>cleared, or'ed, xor'ed, and the like?
>
>I seem to recall that all of this is realized very comfortably in Ada
>9X, but how can I do it in Ada 83?
Devise a package to implement bit operations on your favourite Ada type
(here "word" is a subtype of your favourite integer type).
It would be appropriate, no doubt, to follow the facilities available in
package interfaces of Ada9x for the shift operations.
-------------------------------------------------------
package body bit_ops is
type int_image is array(1..word'size) of boolean;
pragma pack(int_image);
function int_to_array is new unchecked_conversion
(source => word,
target => int_image);
function array_to_int is new unchecked_conversion
(source => int_image,
target => word);
function "xor"(w,w1:word) return word is
a,a1:int_image;
begin
a:= int_to_array(w);
a1 := int_to_array(w1);
return(array_to_int(a xor a1));
end;
function "or"(w, w1 :word) return word is
a, a1 : int_image;
begin
a:= int_to_array(w);
a1 := int_to_array(w1);
return(array_to_int(a or a1));
end;
function "and"(w, w1 : emtypes.word) return word is
a, a1 : int_image;
begin
a := int_to_array(w);
a1 := int_to_array(w1);
return(array_to_int(a and a1));
end;
function "not"(w : word) return word is
a : int_image;
begin
a := int_to_array(w);
return(array_to_int(not a));
end;
end bit_ops;
Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...
next prev parent reply other threads:[~1994-10-26 0:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-10-25 10:36 Flags in Ada? Andre Spiegel
1994-10-25 10:07 ` David Emery
1994-10-25 16:19 ` Norman H. Cohen
1994-10-26 3:19 ` tmoran
1994-10-26 9:59 ` David Emery
1994-10-26 22:32 ` Robert Dewar
1994-10-27 13:24 ` Norman H. Cohen
1994-10-27 15:15 ` John Volan
1994-10-31 9:29 ` David Emery
1994-10-27 22:34 ` Henry G. Baker
1994-10-26 14:33 ` Robert Dewar
1994-10-26 17:43 ` Norman H. Cohen
1994-10-26 15:54 ` Andre Spiegel
1994-10-26 0:36 ` Dale Stanbrough [this message]
1994-10-26 11:01 ` Robert Dewar
1994-10-27 8:23 ` Henri Altarac
1994-10-27 23:00 ` Robert Dewar
1994-10-31 9:32 ` David Emery
-- strict thread matches above, loose matches on Subject: below --
1994-10-25 16:22 tmoran
1994-10-27 5:05 tmoran
1994-10-27 13:29 ` Robert Dewar
1994-10-27 17:15 ` Norman H. Cohen
1994-10-28 3:51 ` Robert Dewar
1994-10-27 5:06 tmoran
1994-10-27 13:47 ` Robert Dewar
1994-10-28 2:41 ` Tucker Taft
1994-10-30 13:31 ` Robert Dewar
1994-10-28 3:59 tmoran
1994-10-28 13:43 ` Robert Dewar
1994-10-31 14:19 ` Norman H. Cohen
1994-11-02 14:06 ` Mats Weber
1994-11-03 23:08 ` Robert Dewar
1994-11-03 11:26 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox