comp.lang.ada
 help / color / mirror / Atom feed
* Re: Generic Pointer Type
@ 1993-09-04  0:17 Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1993-09-04  0:17 UTC (permalink / raw)


Well of course you can't declare a "pointer to void" or anything like that
in Ada, since this the epitome of unsafe programming (a pointer that you
want to keep secret, i.e. you refuse to tell me what it points to, and 
intend to make it point to anything you like later on).

To the limited extent that such a notion is required, explicit
unchecked conversions must be used.

What's the exact problem, it is probably instructive to look at it to see
why a C programmer would want a void pointer, and how an Ada programmer
would avoid it, or never even think of it in the first place!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-07 15:58 Norman H. Cohen
  0 siblings, 0 replies; 8+ messages in thread
From: Norman H. Cohen @ 1993-09-07 15:58 UTC (permalink / raw)


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, how
|> 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.  (For example, unlike a call on malloc, an Ada
allocator returns a value of the desired access type.)  Others are
considered to be of questionable propriety in Ada.  (For example, there
is a way to convert an access value pointing to type A to an access value
pointing to type B so that an object of type A can be manipulated as if
it were of type B.  This is sometimes necessary, but in most cases there
are better ways to get the job done.)

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.

--
Norman H. Cohen    ncohen@watson.ibm.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-07 19:18 dog.ee.lbl.gov!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!swrind
  0 siblings, 0 replies; 8+ messages in thread
From: dog.ee.lbl.gov!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!swrind @ 1993-09-07 19:18 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-08 15:51 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
  0 siblings, 0 replies; 8+ messages in thread
From: cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers @ 1993-09-08 15:51 UTC (permalink / raw)


In article <7SEP199313180978@cl2.cl.uh.edu> SWEN1FBE@cl.uh.edu writes:
>>
>>  [deletia]
>
>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 

It is difficult to understand how using Unchecked_Conversion "goes outside
the standard for Ada" when the standard defines Unchecked_Conversion...

Granted that unchecked programming is not something to do everywhere. But 
this idea that Unchecked_Conversion and Unchecked_Deallocation are somehow
responsible for the invocation of demons is rather unrealistic.  They
have their uses.  Hide them and get on with it.

pat rogers
sbs engineering

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-08 18:36 David Emery
  0 siblings, 0 replies; 8+ messages in thread
From: David Emery @ 1993-09-08 18:36 UTC (permalink / raw)


There is no guarantee *within the language* that any unchecked
conversion will have any meaning.  In particular, there are systems
where you *cannot* convert between arbitrary access types in any
meaningful sense.  For instance, access to scalar may be the address
of the object, but access to array may be a structure holding the
first index, length and address of the first element.  In this case,
integer_access'size /= array_access'size.  Another problem can occur
with collections.  An access value may be an offset within a given
collection.  Two access types may define different collections, so
that converting from one to another produces a 'meaningless' value,
because the access values are not addresses, but are offsets within
different collections, and the 'collection address' is NOT stored with
the access value.

That's how Unchecked_Conversion is "outside of the language".  The WG9
Uniformity Rapporteur Group has been studying this problem for quite
some time, and produced some recommendations for Ada83.  Note that
Ada9X addresses part of this problem within the scope of the language.

Anytime you use Unchecked_Conversion, you incur a portability risk.
This doesn't mean "don't do it", but it means that "understand what
you're doing."

				dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-08 19:25 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
  0 siblings, 0 replies; 8+ messages in thread
From: cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers @ 1993-09-08 19:25 UTC (permalink / raw)


In article <EMERY.93Sep8133649@goldfinger.mitre.org> emery@goldfinger.mitre.org
 (David Emery) writes:
>
[much good stuff]

>Anytime you use Unchecked_Conversion, you incur a portability risk.
>This doesn't mean "don't do it", but it means that "understand what
>you're doing."
>
>				dave

Which is why I wrote:

> Granted that unchecked programming is not something to do everywhere. But 
> this idea that Unchecked_Conversion and Unchecked_Deallocation are somehow
> responsible for the invocation of demons is rather unrealistic.  They
> have their uses.  Hide them and get on with it.

The idea that use of unchecked programming ( conversion and deallocation )
is "against the spirit of Ada" or even illegal is how I interpreted the
original post, as such has been said too many times in the past (not by you,
Dave).  The original poster said "go outside the standard", and "bad thing"
so I answered accordingly.  I was not suggesting that unchecked_conversion
is always well-defined or always a "good thing", just that they will not
cause plagues, as is so often thought by those new to the language.

pat rogers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-09 14:59 Wes Groleau x1240 C73-8
  0 siblings, 0 replies; 8+ messages in thread
From: Wes Groleau x1240 C73-8 @ 1993-09-09 14:59 UTC (permalink / raw)


In article <EMERY.93Sep8133649@goldfinger.mitre.org> emery@goldfinger.mitre.org
 (David Emery) writes:
>There is no guarantee *within the language* that any unchecked
>conversion will have any meaning.  In particular, there are systems
>where you *cannot* convert between arbitrary access types in any
>meaningful sense.  For instance, access to scalar may be the address
>of the object, but access to array may be a structure holding the
>first index, length and address of the first element.  .......

This reminds me of another mistake made by many:  doing an unchecked conversion
between an access type for an object and the address of an object of the same
type.  Even if access types are addresses (they USUALLY are...) the access to
an array is often the address of a structure like the one David mentioned,
while the address of the array is actually the address of the array.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Generic Pointer Type
@ 1993-09-09 17:44 Bev in R. Brett
  0 siblings, 0 replies; 8+ messages in thread
From: Bev in R. Brett @ 1993-09-09 17:44 UTC (permalink / raw)


In article <CD3DMI.JJA@crdnns.crd.ge.com>, groleau@e7sa.crd.ge.com (Wes Groleau
 x1240 C73-8) writes...
>In article <EMERY.93Sep8133649@goldfinger.mitre.org> emery@goldfinger.mitre.or
g (David Emery) writes:
>>There is no guarantee *within the language* that any unchecked
>>conversion will have any meaning.  In particular, there are systems
>>where you *cannot* convert between arbitrary access types in any
>>meaningful sense.  For instance, access to scalar may be the address
>>of the object, but access to array may be a structure holding the
>>first index, length and address of the first element.  .......
> 
>This reminds me of another mistake made by many:  doing an unchecked conversio
n
>between an access type for an object and the address of an object of the same
>type.  Even if access types are addresses (they USUALLY are...) the access to
>an array is often the address of a structure like the one David mentioned,
>while the address of the array is actually the address of the array.

The DEC Ada compilers issue warnings in such situations.

/Bevin

ps: All the rest of this message is designed to fool some stupid piece of s/w
into posting the above, even though it is mainly a quote
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1993-09-09 17:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-04  0:17 Generic Pointer Type Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1993-09-07 15:58 Norman H. Cohen
1993-09-07 19:18 dog.ee.lbl.gov!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!swrind
1993-09-08 15:51 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
1993-09-08 18:36 David Emery
1993-09-08 19:25 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
1993-09-09 14:59 Wes Groleau x1240 C73-8
1993-09-09 17:44 Bev in R. Brett

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