comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: Re: Q: Interfacing C/ADA: Indirect Calls
Date: Wed, 18 Apr 2001 10:53:10 -0400
Date: 2001-04-18T14:53:12+00:00	[thread overview]
Message-ID: <9bk9oo$3oe$1@nh.pace.co.uk> (raw)
In-Reply-To: 9bk6ef$reo$01$1@news.t-online.com

It is very much like a reference to an object by memory address. In some
implementations of Ada, it will degenerate to exactly that. (As has been
observed in the past, access types are not simply addresses, because they do
more and may contain more information than just an address) For practical
usage, you can *think* of them as if they were just addresses, only with a
bunch of restrictions. An access object can only contain an object address
of some specific type. (Could be to a class-wide tagged type, so it is a bit
more flexible than might initially appear.) They used to be used pretty much
exclusively for dynamically allocated objects (roughly equivalent to
malloc's in C) but in Ada95 they can now point to just about anything. The
language rules that apply to access types are there for your safety. (You
can circumvent them, but you should have a good reason to do so.) They
attempt to guarantee that you can't leave around dangling references to
things that no longer exist.

Access types can be very powerful, but are not the most simple part of the
language. There is often a temptation on the part of C/C++ programmers to
over-utilize them. (For example, in passing parameters to subroutines to
achieve "pass by reference" when Ada is perfectly willing to handle all this
for you without you're having to get pointers to everything in sight.) If
you employ the use of access types, try to limit their scope and isolate
them as best you can. (For example, in building a linked list package) You
*really* don't need them anywhere near as much as you do in C/C++ so if you
find yourself using them all over the place, check your assumptions.
Otherwise, you can generally think of them as being similar to SomeType*
variables.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Tilman Glotzner" <Tilman.Gloetzner@uundz.de> wrote in message
news:9bk6ef$reo$01$1@news.t-online.com...
> That works --  Great.
>
> For my curiousity: What exactly is an access type ? Apperently, it is not
a
> reference to an object by memory address (like C references an object).
>
> Thanks,
>
> Tilman
>
> "Florian Weimer" <fw@deneb.enyo.de> schrieb im Newsbeitrag
> news:87n19emnv8.fsf@deneb.enyo.de...
> > Tilman Gloetzner <Tilman.Gloetzner@uundz.de> writes:
> >
> > > use_indirect.adb:10:08: subprogram has invalid convention for context
> > > use_indirect.adb:16:08: subprogram has invalid convention for context
> >
> > I think you have to insert
> >
> >    pragma Convention (C, Indirect_Func);
> >
> > to change the convention of the access-to-subprogram type.
>
>





      reply	other threads:[~2001-04-18 14:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-18 12:54 Q: Interfacing C/ADA: Indirect Calls Tilman Gloetzner
2001-04-18 11:46 ` Florian Weimer
2001-04-18 13:56   ` Tilman Glotzner
2001-04-18 14:53     ` Marin David Condic [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