J3/04-408r1
Date: 09 Nov 2004
To: J3
From: Rob James
Subject: Kinds of intrinsic type parameters - f2003 interp
NUMBER: F03/0020
TITLE: Kinds of intrinsic type parameters
KEYWORDS: type parameter, kind, intrinsic type
DEFECT TYPE: Errata
STATUS: Submitted
QUESTION:
Q1. What are the kinds of the type parameters for intrinsic types?
In most contexts, it doesn't matter. Fortran 95 did not even
have the concept of the kind of a type parameter or a context
in which such a thing could be detected in a
standard-conforming program. Fortran 2003 added the concept
in support of derived types. It also added a syntax which
exposes the question for intrinsic types.
Q2. What is the KIND of a type parameter inquiry?
Q3. For example, consider the program
program what_kind
character c
write (*,*) kind(c%kind) == kind(0)
write (*,*) kind(c%len) == kind(0)
end
Are both write statements guaranteed to print .true. (meaning
that the c%kind and c%len are of default kind) or not?
For KIND parameters, although I can't find it explicitly stated,
I see fairly strong evidence that all intrinsic kind parameters
are intended to be default integers. This evidence is in the
intrinsic functions. The KIND intrinsic function and all the
selected_*_kind functions are specified to return default
integers, which would make for some strangeness if the kind
parameters were not default integer, in particular if the KIND
intrinsic could not return the kind of its argument because that
kind could not be represented in a default integer.
There also seems no obvious benefit to having the kind of the
intrinsic kind parameters be anything other than default. In
practice, the number of supported values for kind is small and
would have no trouble being represented in a default integer;
large arrays of kind values are rare, so there isn't much
benefit in using representations smaller than default.
For character length, I see no similar evidence. Indeed, the
LEN intrinsic seems to suggest that lengths might be other than
default integer. I believe that there was clear intent to
facilitate (but not require) support for character lengths
longer than could be expressed by a default integer.
In most contexts, it doesn't directly matter what the kind of
length is. Parameter specifications in type-specs don't have to
match in kind. So the user could specify and do arithmetic on
lengths using whatever kind was appropriate for the anticipated
problem sizes. The limit on maximum character length is
processor-dependent anyway and is not necessarily the same
as HUGE(whatever) (though it is a bit hard to imagine how it
could usefully be larger).
The only context in which I can see that might matter is in a
type parameter inquiry (6.1.3). We don't appear to have defined
the kind of a type parameter inquiry. Although we didn't say, I
am assuming that a type parameter inquiry ought to "return" the
kind of the type parameter it is inquiring about. Otherwise,
there would be no way to inquire about the type parameter values
of some derived type variables (if the values didn't fit in a
default integer). We probably ought to explicitly say, though.
ANSWER:
Q1. The kind parameters of all the intrinsic types are of
default integer kind. The kind parameter of the intrinsic
character length parameter is processor-dependent.
The support for this answer is as described in the question.
Edits are provided to make this answer explicit.
Q2. The kind parameter of a type inquiry is the same as that of
the type parameter inquired about. See page 123, lines 35-36.
Q3. The first write statement is guaranteed to print a .true. value;
it is processor dependent whether the second one prints a .true.
or .false. value.
EDITS:
All edits apply to 04-007.
At [36:14], [37:30], [39:15], [40:14], and [44:2], insert the
following sentence before "The kind":
The kind type parameter is of type default integer.
At [40:10], before "its", insert "its kind is processor-dependent
and".
SUBMITTED BY: Richard Maine
HISTORY: J3/04-408 m170 Submitted
J3/04-408r1 m170 Edits provided