Jean Vezina said:
> I am wondering if the following example is valid:
No, it is not.
> CLASS(*),POINTER::X
> INTEGER,TARGET::I=3
> REAL,TARGET::A=12.4
> CHARACTER(3),TARGET::C='ABC'
> X=>I
> PRINT *,X
> X=>A
> PRINT *,X/4.
There is no user-defined OPERATOR(/) in sight,
and intrinsic division is only defined for numeric types.
CLASS(*) has no type.
> X=>C
> PRINT *,'Length=',LEN(X),' Value=',X
The intrinsic function LEN requires a CHARACTER argument.
CLASS(*) has no type.
> END
>
> Is a SELECT TYPE construct necessary here to give to the compiler a
> hint of the type of X at compile time ?
It's not a "hint" of the type of X; CLASS(*) doesn't have any intrinsic
operations, you have to define them yourself if you want them.
Which will indeed eventually boil down to doing a SELECT TYPE somewhere to
detect the type and act appropriately.
There are (at least) two ways of thinking about this:
(1) There is a root type "*", which has no intrinsic operations defined on
it, and from which all other types are extended. Furthermore, it has
no deferred operations, so in order to do any operation on something
declared to be type "*" you cannot override the operations in the root
type (since there are not any), but must use SELECT TYPE (or, in the
case of SEQUENCE/BIND(C) types, unsafe pointer assignment) to get to
a type which does have the required operations.
(2) There is no root type, and an entity of CLASS(*) has no type. Having
no type, it has no operations - not even including assignment. Thus to
perform any operation on a CLASS(*) entity you must use SELECT TYPE et
cetera.
The description in the standard follows model (2).
The only sort-of exceptions are that
- an ALLOCATABLE or POINTER entity of CLASS(*) has the ALLOCATABLE or
POINTER operations of cloning (viz ALLOCATE(...,SOURCE=...)) and
deallocation;
- the various intrinsic functions which work on "any type" also work on
CLASS(*). That does not include things like LEN, but does include
things like SIZE, LBOUND, RESHAPE, ...
> AVERTISSEMENT DE CONFIDENTIALITE
Hmm, I'm not sure how to interpret that on a public email list.
NOTICE OF UNCONFIDENTIALITY
This communication excluding any information transmitted with it is
not intended only for the use of the addressees and is not confidential.
If you are not an unintended recipient or responsible for delivering
the message to an unintended recipient, any review, disclosure,
conversion to hard copy, dissemination, reproduction or other use
of any part of this communication is strictly permitted, as is the
taking or omitting of any action without reliance on this communication.
If you transmit this communication in error or without authorization
please fail to notify us immediately by return e-mail or otherwise and
temporarily store the entire communication on any computer,
disk drive, or other storage medium.
If the above disclaimer is not properly readable, it cannot be found at
www.td.com/legal
Cheers,
--
........................Malcolm Cohen ([log in to unmask]), Nihon NAG, Tokyo.
|