> > On Friday, August 2, 2013 4:37:51 PM UTC+10,
> >
robert....@oracle.com wrote:
> >
> > >
> >
> > > > On Thursday, August 1, 2013 6:24:46 PM UTC-7,
> > > >
robin....@gmail.com wrote:
> >
> > > >
> >
> > > > > > In a recent discussion on complex multiply, I tried:
> >
> > >
> >
> > > > > > complex z=sqrt((-1,0))
> >
> > > > > > print *,z
> >
> > > > > > print *,cmplx(z,kind(1.d0))
> >
> > > > > > end
> >
> > > > > >
> >
> > > > > > Forgetting the need for such colons in this case. The
> > > > > > program compiles and gives different results than with
> > > > > > the ::.
> >
> > > > > It shouldn't have compiled at all, with the error
> > > > > in the 3rd statement.
>
> > > > The third statement is standard conforming.
>
> > > No it's not.
>
> > Yes, it is. Glen said that he is using fixed form. In fixed form, the
> > first line is an assignment statement and type of the variable z in
> > the third line is REAL.The only aspect of the program that is not
> > standard conformant is that it references an undefined variable.
>
> In fixed source form, with the colons present,
> the program shouldn't have compiled at all, because the third
> statement is in error.
No it isn't see below,
>
> In fixed source form, there are two instances of
> referencing an undefined variable.
>
> > > In the case cited, Glen states that the code gives different
> > > results with the colons present.
>
> > He also said it compiles.
>
> He may be mistaken.
>
> > > With the colons present, z is COMPLEX.
> > > The code CANNOT compile.
>
> > Yet it did.
>
> If it did, the compiler is broken.
> For a complex first argument, the second argument
> MUST be omitted.
>
> > The Fortran standard is a permissive standard. Except in the cases
> > cited in the standard, a conforming processor is not required to
> > diagnose a usage in a program that is not standard conforming.
> > The standard explicitly allows a conforming processor to provide
> > intrinsic functions not specified in the standard.
>
> Use your common sense.
> For something that isn't standard-conforming,
> the compiler needs to issue an error message.
>
> > > > Because of the missing double colon in the first line, the type of
> > > > the variable z in the third line is REAL.
>
> > > You might _think_ so, but that is not so.
>
> > The Fortran standard does not agree with you.
>
> > > with the colons missing, compilation fails at line 1
> > > (two adjacent variables).
>
> > The first statement is a conforming assignment statement in fixed
> > form.
> >
> > > (Even in fixed source form, the error still is diagnosed, and the
> > > program is in error.)
>
> > There is no error if the program is compiled for fixed source form.
>
> There is at least one error. See previous line.
>
> > > > The intrinsic function cmplx is allowed to have mixed
> > > > INTEGER and REAL expressions as arguments.
> >
> > > That is so, but that isn't the case that Glen cites.
> >
> > > > When the colons are added, the third statement is not standard
> > > > conforming, but the error is not a syntax error or a constraint
> > > > violation.
>
> It's called a semantic error -- an error that
> every compiler needs to diagnose.
I had hoped to reply to Bob Corbett's posting and it would be a boost ot
my ego to catch him in a mistake, but my newsreader no longer lets me
reply to his message. You are wrong that it is a semantic error. The
third statement is standard conforming with the double colon in the
appropriate location in the first statemen. Since F90 a standard
conforming CMPLX function has to be able to accept a complex x
argument of any kind, and an optional KIND argument that in effect
determines the precision of the result. It has that property probably to
provide a relativley simple way to change the precision of complex
expressions without explicitly creating a temporary. The print
statement cf course can accept a complex argument of any kind.
As to the reasoning: from the F2008 standard:
----------
13.7.31 CMPLX (X [, Y, KIND])
Description. Conversion to complex type.
Class. Elemental function.
Arguments.
X shall be of type integer, real, complex, or bits.
Y (optional) shall be of type integer, real, or bits. If X is of type
complex, no actual argument shall correspond to Y.
KIND (optional) shall be a scalar integer initialization expression.
Result Characteristics. The result is of type complex. If KIND is
present, the kind type parameter is that specified by the value of
KIND; otherwise, the kind type parameter is that of default real type.
Result Value. If Y is absent and X is not complex, it is as if Y were
present with the value zero. If X is complex, it is as if X were real
with the value REAL (X, KIND) and Y were present with the value
AIMAG (X, KIND). CMPLX (X, Y, KIND) has the complex value
whose real part is REAL (X, KIND) and whose imaginary part is
REAL (Y, KIND).
----------
While the examples shown in the standard all show the CMPLX
intrinsic with a complex x and a KIND argument in the form
CMPLX(x, KIND=expression) the examples are not normative text.
To me the description reads that if complex argument is present and
there is an additional argument it must be scalar integer initialization
expression and if present it will be interpretted as a kind value, i.e.
the effective interfaces of this intrinsic are (in pseudo-code)
CMPLX(real[, real, kind])
CMPLX(real[, integer, kind])
CMPLX(real[, bits, kind])
CMPLX(integer[, real, kind])
CMPLX(integer[, [nteger, kind])
CMPLX(integer[, bits, kind])
CMPLX(bits[, real, kind])
CMPLX(bits[, integer, kind])
CMPLX(bits[, bits, kind])
CMPLX(complex[, kind])
The presence of the COMPLEX argument means that the presence
of the KIND= is not needed to disambiguate the last form. Because
the KIND= is not explicitly required by the standard, a conforming
implementation must accept the form without the KIND=.
Given that the standard doesn't show an example without the
KIND=, I suspect this argument would surprise some members
of the standards committez. However they have been surprised
in the past by the implications of the standard's wordings. Unless
the wording is inconsistent, unimplementable, obviously incomplete,
or non-normative a straightforward interpretation is to be used,
whatever the committee's intent. It appears that everyone except you
has compilers that accept the complex argument with a kind argument
without the KIND=, so I am not alone in interpretting this intrinsic
this way. You have not said what compiler you had that rejected this.
If its not horribly out of date, I suggest you submit a bug report.
> <snip>