comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <johnvolan@sprintmail.com>
Subject: Re: Conversion of access types ...
Date: 1997/05/03
Date: 1997-05-03T00:00:00+00:00	[thread overview]
Message-ID: <336B8CB6.4A2C@sprintmail.com> (raw)
In-Reply-To: x7vn2qcsbn8.fsf@pogner.demon.co.uk


> t_mjb@linkabit.titan.com writes:
[snip]
> > I am trying to convert a variable of type P to an unsigned long
> > (ULONG) which will allow me to pass this value on to a system
> > procedure which will, when the data finally arrives at its
> > destination, will be converted back into type P.

Well, you could just instantiate Unchecked_Conversion:

    with Ada.Unchecked_Conversion;
    ...
      function P_To_ULONG is new Ada.Unchecked_Conversion (P, ULONG);

      Your_P : P;
      ...
      Your_C_Routine ( ..., P_To_ULONG(Your_P), ...);

But then again, why bother...

Simon Wright wrote:
> 
> I had a similar problem (calls to my own C procedures, actually, but
> equivalent) and found that I could declare the C procedure using the
> Ada access types with pragma Import:
[snip]

Exactly. Remember, everything in the computer is just bits and bytes.
Whether you're talking Ada95 or C or whatever, _all_ data types -- even
seemingly "simple" ones such as integers -- are just abstractions
layered on top of the bits and bytes.  High order languages are really
just an illusion.  It's a very _useful_ illusion, and the discipline of
adhering to that illusion reaps benefits in increased programmer
productivity.  But it's still just an illusion.

So whenever you need to push beyond the boundaries of your programming
language to interface with external hardware or code in other languages,
you have the liberty to pick which illusion you want to map onto the
outside world.

If you have to pretend that those four bytes are something, why bother
pretending they're a ULONG?  You could just as easily pretend they're
your access type directly.  As long as the bit-representation is the
same (you _do_ have to know what you're doing), one pretense is as good
as another! :-)

------------------------------------------------------------------------
Internet.Usenet.Put_Signature 
  (Name => "John G. Volan",  Home_Email => "johnvolan@sprintmail.com",
   Slogan => "Ada95: The World's *FIRST* International-Standard OOPL",
   Disclaimer => "These opinions were never defined, so using them " & 
     "would be erroneous...or is that just nondeterministic now? :-) ");
------------------------------------------------------------------------




      reply	other threads:[~1997-05-03  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-30  0:00 Conversion of access types t_mjb
1997-05-03  0:00 ` Simon Wright
1997-05-03  0:00   ` John G. Volan [this message]
replies disabled

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