Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pointers to substrings in DVF?

0 views
Skip to first unread message

Michael Sanborn

unread,
Jun 24, 1997, 3:00:00 AM6/24/97
to

I'm trying to convert a very old Fortran program to Digital Visual
Fortran. It had used EQUIVALENCE statements to create aliases within
Integer arrays that contained character data. I'd like to declare the
character data as Character type, and I had thought that I might be able
to use pointers to substrings to replace the EQUIVALENCE statments. But
I'm not having any luck yet. As a scaled down version of what I'm trying
to do:

PROGRAM FROG
CHARACTER*18, TARGET :: BUFFER
CHARACTER*3, POINTER :: ONE, TWO
ONE => BUFFER(7:9)
TWO => BUFFER(16:18)
BUFFER = 'Green Eggs and Ham'
PRINT *, ONE
PRINT *, TWO
END

I'm getting 'Gre' and 'Gre'. Is there a way to get 'Egg' and 'Ham'?


Ed Hook

unread,
Jun 24, 1997, 3:00:00 AM6/24/97
to

FWIW, I _think_ that the above should yield 'Egg' and 'Ham'. Here's
what happens with IBM's compiler under AIX:

poseidon1.hook 85 % cat samIam.f

PROGRAM FROG
CHARACTER*18, TARGET :: BUFFER
CHARACTER*3, POINTER :: ONE, TWO
ONE => BUFFER(7:9)
TWO => BUFFER(16:18)
BUFFER = 'Green Eggs and Ham'
PRINT *, ONE
PRINT *, TWO
END

poseidon1.hook 86 % xlf90 -o samIam samIam.f
** frog === End of Compilation 1 ===
1501-510 Compilation successful for file samIam.f.
poseidon1.hook 87 % ./samIam
Egg
Ham
poseidon1.hook 88 %

--
Ed Hook | Copula eam, se non posit
Computer Sciences Corporation | acceptera jocularum.
NASA Langley Research Center | Me? Speak for my employer?...<*snort*>
Internet: ho...@cscsun3.larc.nasa.gov | ... Get a _clue_ !!! ...

Ron Guenther

unread,
Jun 24, 1997, 3:00:00 AM6/24/97
to

Greetings.. I believe the FORTRAN 90 spec states something along the
following line:

A POINTER’s target must have the same type, kind, and shape as the POINTER.

I don't believe you have met this criterion.


Michael Sanborn <mic...@graphion.com> wrote in article
<33B015FD...@graphion.com>...


> I'm trying to convert a very old Fortran program to Digital Visual

> Fortran. It had used EQUIVALENCE statements to create aliases ...

Mike METCALF

unread,
Jun 25, 1997, 3:00:00 AM6/25/97
to

In article <01bc80ed$aa1441b0$c33e0f81@mapinfo2>, gue...@msn.com says...

>
>Greetings.. I believe the FORTRAN 90 spec states something along the
>following line:
>
>A POINTER’s target must have the same type, kind, and shape as the POINTER.
>
>I don't believe you have met this criterion.

Why not. The type is CHARACTER, the kind is default, the rank (not shape) is
zero. So the code is valid. Looks like a compiler bug that you should report
to Digital.

Mike Metcalf

Steve Lionel

unread,
Jun 25, 1997, 3:00:00 AM6/25/97
to

In article <33B015FD...@graphion.com>, Michael Sanborn
<mic...@graphion.com> writes:

|>I'm trying to convert a very old Fortran program to Digital Visual

|>Fortran. It had used EQUIVALENCE statements to create aliases within
|>Integer arrays that contained character data. I'd like to declare the
|>character data as Character type, and I had thought that I might be able

|>to use pointers to substrings to replace the EQUIVALENCE statments. But


|>I'm not having any luck yet. As a scaled down version of what I'm trying
|>to do:
|>
|> PROGRAM FROG
|> CHARACTER*18, TARGET :: BUFFER
|> CHARACTER*3, POINTER :: ONE, TWO
|> ONE => BUFFER(7:9)
|> TWO => BUFFER(16:18)

|> BUFFER = 'Green Eggs and Ham'
|> PRINT *, ONE
|> PRINT *, TWO
|> END
|>
|>I'm getting 'Gre' and 'Gre'. Is there a way to get 'Egg' and 'Ham'?

This does indeed look like a bug in DVF. We'll take a look at it. The
following alternative does work, but it uses an extension.

PROGRAM FROG
CHARACTER*18, TARGET :: BUFFER

CHARACTER*3 :: ONE, TWO
POINTER (P_ONE, ONE)
POINTER (P_TWO, TWO)
P_ONE = %LOC(BUFFER(7:9))
P_TWO = %LOC(BUFFER(16:18))


BUFFER = 'Green Eggs and Ham'
PRINT *, ONE
PRINT *, TWO
END

--
Please send DIGITAL Visual Fortran support requests to dvf-s...@digital.com

Steve Lionel mailto:lio...@mail.dec.com
Fortran Development http://www.digital.com/info/slionel.html
Digital Equipment Corporation
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698 "Free advice is worth every cent"

For information on DIGITAL Fortran, see http://www.digital.com/fortran

Neil Carlson

unread,
Jun 25, 1997, 3:00:00 AM6/25/97
to

Mike METCALF wrote:
>
> In article <01bc80ed$aa1441b0$c33e0f81@mapinfo2>, gue...@msn.com says...
> >
> >Greetings.. I believe the FORTRAN 90 spec states something along the
> >following line:
> >
> >A POINTER’s target must have the same type, kind, and shape as the POINTER.
> >
> >I don't believe you have met this criterion.
>
> Why not. The type is CHARACTER, the kind is default, the rank (not shape) is
> zero. So the code is valid. Looks like a compiler bug that you should report
> to Digital.

This was my first reaction too but the F90 Handbook states

"The type, type parameters, (kind and length, if character), and
rank of the target must be the same as the pointer object"

(Your F book says the same! :-) In this example the lengths differ.

Neil
---------------------------------------------------------------------------
Neil N. Carlson car...@math.purdue.edu
Department of Mathematics 765-494-1920 (Fax: 4-0548)
Purdue University
---------------------------------------------------------------------------

Neil Carlson

unread,
Jun 25, 1997, 3:00:00 AM6/25/97
to Michael Metcalf

Michael Metcalf wrote:
>
> But the lengths are the same: 3 on each side of each assignment!

Arghhh! I spoke too quickly; you're absolutely correct.

Neil

Jean Vezina

unread,
Jun 25, 1997, 3:00:00 AM6/25/97
to Neil Carlson

Neil Carlson wrote:
>
> This was my first reaction too but the F90 Handbook states
>
> "The type, type parameters, (kind and length, if character), and
> rank of the target must be the same as the pointer object"
>
> (Your F book says the same! :-) In this example the lengths differ.
>
> Neil

The lengths doesn't differ, since the SUBSTRINGS of the variables have a
length of 3 (Check it with LEN). The pointer assignments are done to
substrings of the original variables.

Regards,

Jean Vezina

0 new messages