comp.lang.ada
 help / color / mirror / Atom feed
From: Mark A Biggar <mark.a.biggar@lmco.com>
Subject: Re: Or
Date: 2000/01/31
Date: 2000-01-31T00:00:00+00:00	[thread overview]
Message-ID: <3895E3B6.B083193@lmco.com> (raw)
In-Reply-To: vhioga2t8wa.fsf@ljod.ifi.uio.no

Jan Kroken wrote:
> 
> I need bitwise or on Interfaces.C.Int. I couldn't find any
> direct or operator in Ada, so I wrote the following:
> 
>    function C_Or (R: C.Int;
>                   L: C.Int) return C.Int
>    is
>       type Int_Access is access all C.Int;
>       package A2A is new System.Address_To_Access_Conversions(C.Int);
>       X,Y,Result: aliased C.Int;
>       XA,YA,RA: System.Address;
>       RP : Int_Access;
>    begin
>       X := R;
>       Y := L;
>       XA := A2A.To_Address(X'Access);
>       YA := A2A.To_Address(Y'Access);
>       RA := A2A.To_Address(Result'Access);
>       System.Bit_Ops.Bit_Or(XA,32,YA,32,RA);
>       return A2A.To_Pointer(RA).all;
>    end C_Or;
>    pragma Inline(C_Or);

You might try something like:

function C_Or (R: C.Int;
               L: C.Int) return C.Int
is
    subtype Unsigned is C.Unsigned;
    function to_Unsigned(X: C.int) return Unsigned is
	new Unchecked_Conversion(C.Int, Unsigned);
    function to_Int(X: Unsigned) return C.Int is
	new Unchecked_conversion(Unsigned, C.Int);
begin
    return to_Int(to_Unsigned(R) or to_Unsigned(L));
end C_Or;
pragma Inline(C_Or);

--
Mark Biggar
mark.a.biggar@lmco.com




  parent reply	other threads:[~2000-01-31  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <vhioga2t8wa.fsf@ljod.ifi.uio.no>
2000-01-31  0:00 ` Or David Starner
2000-01-31  0:00 ` Or Gisle S�lensminde
2000-01-31  0:00 ` Mark A Biggar [this message]
2000-01-31  0:00 ` Or Vladimir Olensky
2000-01-31  0:00 ` Or tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox