comp.lang.ada
 help / color / mirror / Atom feed
From: dewarr@my-dejanews.com
Subject: Re: access_to_constant as subprogram paramater
Date: 1998/09/20
Date: 1998-09-20T00:00:00+00:00	[thread overview]
Message-ID: <6u2p9m$qe3$1@nnrp1.dejanews.com> (raw)
In-Reply-To: EzJo6C.5EC.0.-s@inmet.camb.inmet.com

In article <EzJo6C.5EC.0.-s@inmet.camb.inmet.com>,
  stt@houdini.camb.inmet.com (Tucker Taft) wrote:

> In any case, you can just use a named access-to-constant
> type in many cases, or even simpler, a plain old "IN" parameter.

Very good advice. Let me state a definite rule:

NEVER use an access mode parameter if you can use a normal
IN or IN OUT mode parameter in its place.

People have got into a LOT of trouble ignoring this rule.
For example, some of the early versions of the Intermetrics
bindings done for Ada 95 were peppered with incorrect uses
of access parameters to model C pointers. This doesn't work
because nearly all the routines expected to be able to deal
with null values for the parameters, and there is of course
no way to pass a null value to an access parameter (if you
think you can simply use NULL as the actual, then it shows
a mismatch between your conception of the language feature
and the actual feature that is there -- that indeed is the
worst feature of this Ada construct, it invites this
mismatch!)

The proper way to model a C pointer is (how amazing!) with
an Ada access value for which pragma Convention (C) is given.
Most likely you don't need the pragma Convention, but if you
are being hyper-correct it should be there.

Note that you generally cannot pass a pointer-to-unconstrained
backwards and forwards to C, for the simple reason that this
type corresponds to nothing at all in C.


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




      reply	other threads:[~1998-09-20  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-19  0:00 access_to_constant as subprogram paramater nelson
1998-09-19  0:00 ` David C. Hoos, Sr
1998-09-19  0:00 ` dewarr
1998-09-19  0:00 ` Tucker Taft
1998-09-20  0:00   ` dewarr [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