From: tmoran@bix.com
Subject: Re: Or
Date: 2000/01/31
Date: 2000-01-31T00:00:00+00:00 [thread overview]
Message-ID: <Y9ll4.15$SR1.1562@nnrp3-w.snfc21.pbi.net> (raw)
In-Reply-To: vhioga2t8wa.fsf@ljod.ifi.uio.no
>I need bitwise or on Interfaces.C.Int. I couldn't find any
>direct or operator in Ada,
What are you using for a manual for Ada?
-- assuming Interfaces.C.Int and Unsigned are the same size:
function Ignore_Sign is new Ada.Unchecked_Conversion
(source=>Interfaces.C.Int, target=>Interfaces.C.Unsigned);
function Xlate_Sign is new Ada.Unchecked_Conversion
(source=>Interfaces.C.Unsigned, target=>Interfaces.C.Int);
A, B, Result : Interfaces.C.Int;
...
Result := Xlate_Sign(Ignore_Sign(A) or Ignore_Sign(B));
But if you really want to do ORs, presumably your variables
are all Unsigned, not Int, anyway, so
A, B, Result : Interfaces.C.Unsigned;
...
Result := A or B;
> 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);
A good rule of thumb with Ada is "If it's hard, you're approaching
it wrong".
next 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 ` tmoran [this message]
2000-01-31 0:00 ` Or Vladimir Olensky
2000-01-31 0:00 ` Or Gisle S�lensminde
2000-01-31 0:00 ` Or Mark A Biggar
2000-01-31 0:00 ` Or David Starner
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox