Re: Pointer arithmetic with C_F_POINTER
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Thu, 19 Jun 2008 11:01:48 -0700
Dennis Wassel <dennis.wassel@xxxxxxxxxxxxxx> wrote:
...Pointer arithmetic in Fortran...
Others are answering in more detail, but the short answer is that
Fortran does not support pointer arithmetic. This is very deliberate and
opinions on the committee were quite vehement about it.
I'll go on to make that short answer long in my usual way. :-)
In fact, the opinions on this were so vehement that they were probably
the single largest objection to the whole C interop facility of F2003,
and in particular to the C_LOC and C_F_POINTER procedures. I had tried
to get the functionality of those procedures into C interop, but I was
shot down by vehement objections from people who noticed that this made
it easier for programmers to sneak C pointer arithmetic stuff into their
Fortran code.
Some people just had an awfully hard time accepting that if Fortran was
going to be able to interoperate with C, that inherently meant that the
Fortran compiler was not going to be able to protect people against
errors in the C code.
My proposal for C_LOC and C_F_POINTER lost badly. But far later in the
process, when people outside the committee were starting to look at how
they would use the C interop stuff, they discovered exactly the same
major hindrances that had led me to want this functionality. One huge
one was that without this functionality, you couldn't have a Fortran
procedure call something in C that returned dynamically-sized data with
the allocation done in the C part. The outside people who were working
on this were also working with the convenor of WG5 (the international
ortan committee). There complaints ended up having sufficient weight to
revive the C_LOC and C_F_POINTER proposals (once I pointed out how that
proposal addressed the complaints), which then did make it into the
published standard.
As a result of these procedures, you can badly mess up your Fortran
propgram by doing the "wrong" things with C pointer arithmetic. The
things that will mess you up are nonstandard, but the compiler is very
unlikely to be able to diagnose the problems. That just comes with the
territory of C interop.
If you want to use pointer arithmetic, you pretty much have to do it in
C, or at least in pseudo-C and it is pretty much up to you not to screw
it up. In partial answer to your followup question, C_LOC gives you a C
void pointer. It doesn't have type information - just an address. You
are just supposed to "know" what the appropriate type is, as the
compiler doesn't.
The odds of pointer arithmetic getting added directly to Fortran are
low. Even the suggestion is likely to elicit cries of "I told you so; we
should never have let that camel's nose in this tent" from those people
who so vehemently objected to CLOC and C_F_POINTER in the first place.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Pointer arithmetic with C_F_POINTER
- From: Dennis Wassel
- Re: Pointer arithmetic with C_F_POINTER
- From: Dennis Wassel
- Re: Pointer arithmetic with C_F_POINTER
- References:
- Pointer arithmetic with C_F_POINTER
- From: Dennis Wassel
- Pointer arithmetic with C_F_POINTER
- Prev by Date: Re: PGI wierdness with .EQV.
- Next by Date: Re: does fortran recognize sets
- Previous by thread: Re: Pointer arithmetic with C_F_POINTER
- Next by thread: Re: Pointer arithmetic with C_F_POINTER
- Index(es):
Relevant Pages
|
|