comp.lang.ada
 help / color / mirror / Atom feed
From: dog.ee.lbl.gov!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!swrind e!menudo.uh.edu!cl2.cl.uh.edu!swen1fbe@ucbvax.Berkeley.EDU  (Tim D.)
Subject: Re: Generic Pointer Type
Date: 7 Sep 93 19:18:00 GMT	[thread overview]
Message-ID: <7SEP199313180978@cl2.cl.uh.edu> (raw)

In article <CCzr27.ICA@yktnews.watson.ibm.com>, ncohen@watson.ibm.com writes...
>In article <2689cj$4m1@pdq.coe.montana.edu>, hoffman@cs.montana.edu (Brad
>Hoffman) writes: 
> 
>|> Hello, I am a serious Ada rookie and am trying to figure out if it is
>|> possible to declare a "void-type pointer".  Is this possible, and if so, ho
w
>|> do I do it?
> 
>The short answer is no:  Every access type in Ada is declared to point to
>objects of one particular type.
> 
>The longer answer is:  Ada has various mechanisms for doing the kinds of
>things C programmers do with void *.  Some of these things are
>unnecessary in Ada.  [DELETED TEXT]
>
>Why don't you tell us what problem led you to believe you needed a
>void-type pointer?  Then we can discuss the way that problem is solved in
>Ada.

Part of the philosophy behind Ada is the idea that untypeid pointers are
a bad idea.  (however, it does support addressing some.)

Even more important:  conversion between two access types goes outside
the standard for ada--ie, it requires unchecked_conversion.  Any suggestions to
 
use this feature should be accompanied with the caveats:  This might not work 
on your system. and This is not portable.  

Consider the conversion between two access types:

with unchecked_conversion;

procedure dummy is

   type a is access string;
   type s10 is string(1..10);
   type b is access s10;

   function convert is new unchecked_conversion(b,a);

   x : a;  
   y : b;

begin

   y := new s10;

   x := convert(y);

end dummy;

When I compile this code in VAX Ada, I get the following message:

Line  9:           function convert is new unchecked_conversion(b,a);
Line  18:          x := convert(y);
%ADAC-I-UNCH_CONV_SUSPE, This unchecked conversion (function body convert at
        line 9 (from predefined UNCHECKED_CONVERSION)) is suspect

Line  5:           type a is access string;
Line  7:           type b is access s10;
Line  18:          x := convert(y);
%ADAC-I-UNCH_CONV_ACC_1, The representation of access type a at line 5 is the
        address of a descriptor (because the designated array type STRING in
        predefined STANDARD is unconstrained), while the representation of
        access type b at line 7 is the address of the designated object

So, not all access types are equivalent.  Likewise, conversions between
access types and addresses are suspect.  

Depending on the need, you might considered using "based" variables--ie,
defining an ada entity to physically reside at a certain address.

             reply	other threads:[~1993-09-07 19:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-07 19:18 dog.ee.lbl.gov!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!swrind [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-09 17:44 Generic Pointer Type Bev in R. Brett
1993-09-09 14:59 Wes Groleau x1240 C73-8
1993-09-08 19:25 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
1993-09-08 18:36 David Emery
1993-09-08 15:51 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
1993-09-07 15:58 Norman H. Cohen
1993-09-04  0:17 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