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

compilation problem : abstract type and deferred procedure

16 views
Skip to first unread message

AT

unread,
Sep 7, 2010, 4:54:53 PM9/7/10
to
As an exercise ( I learn Fortran up to F2003 - with great pleasure by
the way ) I tried to write a small program using an abstract type and a
deferred function ( code below ).
As it is:
Using ifort I got an Internal Compiler Error ( and posted something at
the Intel compiler forum )
Using gfortran I have an error:
myPoint = point2d(2.3, 4.2)
1
Error: Invalid character in name at (1)

Replacing this line by :
myPoint%x = 2.3 ; myPoint%y = 4.2
everything works.

Does someone here see a problem with the code ?

Marc


module pointModule
implicit none

type, abstract :: pointGen
contains
procedure ( compDistToOProto ) , deferred :: compDistToO
end type pointGen

type, extends( pointGen) :: point2d
real :: x
real :: y
contains
procedure :: compDistToO => compDist2dToO
end type point2d

abstract interface
function compDistToOProto( self ) result(distance)
import :: pointGen
class(pointGen) :: self
real :: distance
end function compDistToOProto
end interface

contains
function compDist2dToO( self ) result(distance)
class(point2d) :: self
real :: distance

distance = sqrt( self%x*self%x + self%y*self%y )
end function compDist2dToO

end module pointModule

program letest
use pointModule
implicit none

real :: distance
type(point2d) :: myPoint


myPoint = point2d(2.3, 4.2) ! The problem is here
! myPoint%x = 2.3 ; myPoint%y = 4.2 ! ok with that


distance = myPoint%compDistToO()
print *, "Distance = ", distance
end program letest

Richard Maine

unread,
Sep 7, 2010, 5:17:18 PM9/7/10
to
AT <"gtitus(AT)wanadoo.fr"> wrote:
[code using some f2003 stuff elided]

> Using gfortran I have an error:
> myPoint = point2d(2.3, 4.2)
> 1
> Error: Invalid character in name at (1)
>
> Replacing this line by :
> myPoint%x = 2.3 ; myPoint%y = 4.2
> everything works.
>
> Does someone here see a problem with the code ?

Not off-hand, though I admit to not having studied it very carefully.
That strikes me as a strange error message for the context anyway. It
might almost make me suspicious of something like nonprinting characters
making their way into the source code. I don't have gfortran installed
here to handily test with. I do have g95, but it doesn't (yet?) support
the features used in the code.

Nag compiles and runs the posted code without complaint (assuming I use
the f2003 switch to turn off the warnings about f2003 features being
extensions to f95.)


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

David W Noon

unread,
Sep 7, 2010, 5:58:46 PM9/7/10
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 07 Sep 2010 22:54:53 +0200, AT wrote about compilation
problem : abstract type and deferred procedure:

>Using gfortran I have an error:
>myPoint = point2d(2.3, 4.2)
> 1
>Error: Invalid character in name at (1)

Do you have a tab character in that position, instead of a space?

Try using the -Wtab compilation option to suppress tab detection by the
compiler.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwn...@spamtrap.ntlworld.com (David W Noon)
Remove spam trap to reply by e-mail.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)

iEYEARECAAYFAkyGtZ8ACgkQ9MqaUJQw2MmdaQCgmZFkk+I98BCrpz7J1U6plRDK
RzsAoKp+bQfLUXxV3rxc32HpwD4BueYr
=kUxY
-----END PGP SIGNATURE-----

robert....@oracle.com

unread,
Sep 7, 2010, 10:00:09 PM9/7/10
to
On Sep 7, 1:54 pm, AT <"gtitus(AT)wanadoo.fr"> wrote:
> As an exercise ( I learn Fortran up to F2003 - with great pleasure by
> the way ) I tried to write a small program using an abstract type and a
> deferred function ( code below ).
> As it is:
> Using ifort I got an Internal Compiler Error ( and posted something at
> the Intel compiler forum )
> Using gfortran I have an error:
> myPoint = point2d(2.3, 4.2)
> 1
> Error: Invalid character in name at (1)
>
> Replacing this line by :
> myPoint%x = 2.3 ; myPoint%y = 4.2
> everything works.

What happen if you replace the line with

myPoint = point2d(x=2.3, y=4.2)

?

Bob Corbett

Richard Maine

unread,
Sep 7, 2010, 10:07:04 PM9/7/10
to
<robert....@oracle.com> wrote:

> On Sep 7, 1:54 pm, AT <"gtitus(AT)wanadoo.fr"> wrote:

> > Using gfortran I have an error:
> > myPoint = point2d(2.3, 4.2)
> > 1
> > Error: Invalid character in name at (1)

...


> What happen if you replace the line with
>
> myPoint = point2d(x=2.3, y=4.2)

Hmm. Good point (so to speak). If the compiler were expecting a keyword
form, it might think that the 2 in 2.3 was an invalid initial character
for a keyword. It would still be a compiler bug, but I begin to see how
a plausible compiler bug might generate an error message like that.

P.S. I just noticed your new email domain, Bob. I suppose it figures,
but I hadn't noticed before.

Tobias Burnus

unread,
Sep 8, 2010, 1:27:55 AM9/8/10
to
robert....@oracle.com wrote:
> On Sep 7, 1:54 pm, AT<"gtitus(AT)wanadoo.fr"> wrote:
>> Using gfortran I have an error:
>> myPoint = point2d(2.3, 4.2)
>> 1
>> Error: Invalid character in name at (1)
>>
> What happen if you replace the line with
>
> myPoint = point2d(x=2.3, y=4.2)

It will work; I have now filled a bug report* against gfortran.

Tobias

* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45592

AT

unread,
Sep 8, 2010, 1:43:45 AM9/8/10
to
Le 08/09/10 04:00, robert....@oracle.com a écrit :

> What happen if you replace the line with
>
> myPoint = point2d(x=2.3, y=4.2)
>
> ?
>
> Bob Corbett


If I do so, it is fine for gfortran, and I still have the ICE using
intel fortran. As Richard Maine points out it looks like a compiler bug
( in both cases ), I will learn how to do a gfortran bug report - I am
not very familiar with that ...
Anyway your idea gives me now a workaround. Thanks.

Marc

AT

unread,
Sep 8, 2010, 1:55:04 AM9/8/10
to
Thanks ! I will learn later ( maybe ) how to do this.
Marc


Le 08/09/10 07:27, Tobias Burnus a écrit :

0 new messages