From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 7 Sep 93 19:18:00 GMT 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 Message-ID: <7SEP199313180978@cl2.cl.uh.edu> List-Id: In article , 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.