Re: Possible compiler bug with this simple program



"Niklas Holsti" <niklas.holsti@xxxxxxxxxxxxxxx> wrote in message
news:48b65b3b$0$25384$4f793bc4@xxxxxxxxxxxxxx
....
In fact, when an Ada subprogram has an unconstrained array parameter with
Convention C, it seems to me that the subprogram's body cannot make any
use of individual elements of the array, because it doesn't know the index
range, so the compiler should reject any indexing of such an array
parameter, as well as any attempt to pass it on as a Convention Ada
parameter.

This is the subject of AI05-0002-1. (It was carried over from the Ada 95.)
[Now, I have to go look this one up because I don't remember anything about
what we decided...] Ah, yes:

"We do not require support for C convention interfacing pragmas for
unconstrained
array objects, unconstrained array function results, and most unconstrained
array parameters."

In particular, "An implementation need not support ... an Export or
Convention pragma applied to a subprogram which has a parameter of an
unconstrained array subtype;". The wording goes on to include unconstrained
array objects and function results as well.

Note that an implementation *can* support this if it wants; some
implementations do implement this with various meanings (Tucker reported
that their compiler gives the array maximum bounds) and it was thought to be
bad to break user programs that depend on such behaviors. But if it does
support it, it ought to do something sensible (raising random exceptions
doesn't count). (Also note that it is required to support pragma Import in
this case, as C doesn't care about the bounds and they can just be dropped.)

Conclusion: Your program tries to do something that cannot possibly work,
but the compiler should have told you so.

Well, not necessarily (see Tucker's implementation, for instance). But
either it should do something defined *or* reject it at compile-time.
(Janus/Ada would have rejected the Convention pragma.) In any case, it is
not required to support this in any useful way, and, as it is not portable,
it should be avoided.

Randy.


.



Relevant Pages

  • Re: Possible compiler bug with this simple program
    ... I suspect that one problem is using the C convention to pass a parameter that is of an unconstrained array type, ... B.3, the C convention passes only a single pointer to the first element of the array, so the 'Range attribute will not be available to the subprogram. ... The compiler should IMHO have rejected the use of x'range here, ... In fact, when an Ada subprogram has an unconstrained array parameter with Convention C, it seems to me that the subprogram's body cannot make any use of individual elements of the array, because it doesn't know the index range, so the compiler should reject any indexing of such an array parameter, as well as any attempt to pass it on as a Convention Ada parameter. ...
    (comp.lang.ada)
  • Re: Possible compiler bug with this simple program
    ... because it doesn't know the index range, so the compiler should ... reject any indexing of such an array parameter, ... attempt to pass it on as a Convention Ada parameter. ... When mapform19 is called from a C routine, ...
    (comp.lang.ada)
  • Re: Possible compiler bug with this simple program
    ... Convention C, it seems to me that the subprogram's body cannot make any ... use of individual elements of the array, because it doesn't know the index ... "An implementation need not support ... ... Superficially, in my situation, it appears that GNAT 4.3.0 on OS X PPC ...
    (comp.lang.ada)
  • Re: Array of Objects
    ... is "an array of Side objects". ... In addition, by convention, variables ... to do it in a constructor. ... Steve W. Jackson ...
    (comp.lang.java.help)
  • Re: Language Features Id Like To See
    ... the support for array manipulation in Delphi is relatively weak. ... either $ClassSerialized+ or $Serialized+, using an attribute, compiler ... any type with the memory manager to use. ...
    (borland.public.delphi.non-technical)