comp.lang.ada
 help / color / mirror / Atom feed
From: dewarr@my-dejanews.com
Subject: Re: help with pointerproblem.
Date: 1998/09/12
Date: 1998-09-12T00:00:00+00:00	[thread overview]
Message-ID: <6tdhnq$3ig$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 6ta4lf$e0b1@onews.collins.rockwell.com

In article <6ta4lf$e0b1@onews.collins.rockwell.com>,
  No@Junk.Mail wrote:
>
> Since VertexArray is unconstrained, there will have to be a descriptor
> someplace.  It's likely the pointer points to the descriptor instead
> of the data.  I'd prefer to take the 'address of element zero of the
> array.  Seems to me that's more likely to work across nearly all
> platforms.  Like this:
>
>   return GLPointer (ToGlPointerPackage.To_Pointer (vPtr(0)'Address));
>


This is incorrect, it is in fact rather unlikely that the
pointer points to the descriptor. The two more common ways
of implementing unconstrained pointers are as follows:

1. Fat pointers, as used by GNAT by default. Here the pointer
is two pointers, one to the data and one to the descriptor.

2. Thin pointers, as used by GNAT if a size clause is used
to force single pointer length. Here the pointer is to the
data, but the bounds are just "behind" the data. Many other
Ada compilers have used this technique.

It is actually quite rare to point to a descriptor (I think
that the RR compiler may have done this at least at one
point).

Even if the pointer *does* point to the descriptor, you still
should expect that arr'address is the address of the first
element on an Ada 95 compiler because of RM 13.3(14):

  For an array X, X'Address should point at the first
  component of the array, and not at the array bounds.

This is implementation advice rather than a requirement, but
a compiler is supposed to follow implementation advice unless
there is a good reason not to, and it is hard to imagine that
this obviously good advice would not be followed. Moreover,
if your compiler does not follow it, then this MUST be
documented, this is a requirement of annex M.

If you have an Ada 95 compiler which does not follow this
implementation advice, I would report it as a bug to your
vendor.

Nevertheless, the caution of using the address of the first
element is a reasonably one, which might possibly help you
out with a recalcitrant vendor who for some reason refused
to follow this implementation advice. Most certainly GNAT
DOES follow this advice, and every other Ada 95 compiler
which I am aware of also follows this advice.

Robert Dewar
Ada Core Technologies

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




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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-10  0:00 help with pointerproblem Roger Carlsson
1998-09-10  0:00 ` Steve Doiel
1998-09-11  0:00   ` Wayne Magor
1998-09-11  0:00     ` Mats Weber
1998-09-12  0:00     ` dewarr [this message]
1998-09-17  0:00       ` Matthew Heaney
1998-09-11  0:00 ` Mats Weber
replies disabled

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