Re: Reference to derived type element by index?



James Van Buskirk <not_valid@xxxxxxxxxxx> wrote:

Since C binding was introduced, you can point at any TARGET with
any kind of pointer you want, just like in C.

And just like in C, that doesn't actually mean it is standard conforming
or portable. It just means that the compiler isn't likely to bitch about
it; whether it works as intended is another matter entirely.

Thus in the above I have pointed at the four REAL elements of circle1
with a pointer to an array of REALs, and accessed them as an array
of REALs.

Yep. Odds are even fairly good that it will work in most environments.
But it is *NOT* standard conforming. If you find an environment where it
fails, you'll have no recourse.

The standard doesn't specify that the components are stored in that way.
This isn't even a matter of having to read the whole standard and
concluding that one couldn't find such a specification. The standard
explicitly says that there is no such specification.

You might improve the odds by making the type a sequence type. Even
then, it isn't guaranteed because the type wouldn't be a numeric
sequence.

You might improve them even more by making it a bind(c) type. I don't
recall C's rules on this kind of thing.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.