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

F2003 standard question: Generic resolution and passing a "string" to a character(len=1), dimension(*) dummy

16 views
Skip to first unread message

Tobias Burnus

unread,
Dec 12, 2008, 9:52:39 AM12/12/08
to
Hello,

since F2003 one can pass a "string" to a character(len=1),dimension(*)
dummy. The question is whether this should also work for generic
resolution or not.

The "call One('String')" (one = generic name) of the following program
is rejected by gfortran, ifort, NAG f95 and g95, stating that no
matching specific procedure could be found. On the other hand, all of
them accept "call Two" (= specific name). My question is now whether
"call One" should work as well (which would indicate a bug in all four
compilers) or not.

My gut feeling is that it is valid, but I cannot really pin point it in
the standard.*

Another question: Am I reading it correctly that if the default kind has
not the same value as "UCS4 = selected_char_kind('ISO_10646')" then a
call with an actual argument ucs4_"string" to a procedure with
array-valued ucs4-kind dummy argument is invalid Fortran 2003 and should
be rejected by the compiler with -std=f2003? This also holds for Fortran
2008 (current draft), does it?**


MODULE modtest
USE ISO_C_BINDING
INTERFACE One
MODULE PROCEDURE Two
h END INTERFACE
CONTAINS
SUBROUTINE Two( chr ) bind(C)
CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*) :: chr
END SUBROUTINE Two
END MODULE modtest

PROGRAM main
USE ISO_C_BINDING
USE modtest
CHARACTER(LEN=4, KIND=C_CHAR) :: chrScalar
chrScalar = 'Scal'
CALL One( chrScalar )
CALL Two( chrScalar )
END PROGRAM main

Tobias

* Regarding the standard, I think "12.4.1.5 Sequence association" is the
most important section, but I also looked at "12.4.1.2 Actual arguments
associated with dummy data objects", "16.4.3 Storage association" and
(for c_char) "15.2 Interoperability between Fortran and C entities".

** "12.5.2.11 Sequence association" also talks about default kind and
c_char only.

Reinhold Bader

unread,
Dec 12, 2008, 11:29:49 AM12/12/08
to
Hello,

Tobias Burnus schrieb:


> Hello,
>
> since F2003 one can pass a "string" to a character(len=1),dimension(*)
> dummy. The question is whether this should also work for generic
> resolution or not.

For handing on c_char scalars to char * an exception was made in F2003,
allowing scalars to be matched to an entity with the dimension(*) attribute;
otherwise dimension(*) will match arrays only, though of arbitrary dimension.

For generics, the "R" part of the TKR rule applies, which prohibits *both* above cases.
The Fortran 2003 standard says (p270, 27-29)
"If the procedure is nonelemental and is referenced by a generic name or as
a defined operator or defined assignment, the ranks of the actual arguments
and corresponding dummy arguments shall agree."

Regards
Reinhold

0 new messages