Re: bug in g95 with character arrays?
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Sat, 28 Jun 2008 10:03:49 -0800
Richard Maine wrote:
wim <wim.van.hoydonck@xxxxxxxxx> wrote:
character(len=5), parameter :: test(5) =
["tan","atan2","atan","sin","asin"]
1
Error: Element in character array constructor at (1) has length 5
instead of 3
No, this is not a bug in g95. It is a bug in your code. This was(snip)
essentially the first interpretation question I ever asked about f90. I
read the standard and had trouble imagining that things would really
this way because it was so much of a PITA - shades of Pascal - so I
posted a question about it here.
Is this another side effect of the rule that the right side
of an assignment (even though it isn't an assignment) doesn't
depend on the type on the left?
My first thought is that it should work for a DATA statement,
but now I am not even sure about that.
(snip)
In f2003, you can explicitly specify the type and type parameters for an
array constructor. This has several effects, one of which is that the
elements in the constructor can have diferent types and type parameters
as long as the needed intrinsic conversion exists.
Thus your example can be written in f2003 as
character(len=5), parameter :: test(5) = &
[character(len=5) :: "tan","atan2","atan","sin","asin"]
Although that looks a bit redundant, it does the job. The apparent
redundancy is because the array constructor does not pick up its type
and type parameters from context. See many, many questions about the
more general case of that principle (most often relating to precision of
reals).
One might think that PARAMETER was different, but it
seems that it isn't.
-- glen
.
- Follow-Ups:
- Re: bug in g95 with character arrays?
- From: Richard Maine
- Re: bug in g95 with character arrays?
- References:
- bug in g95 with character arrays?
- From: wim
- Re: bug in g95 with character arrays?
- From: Richard Maine
- bug in g95 with character arrays?
- Prev by Date: Re: Is it time to legitimise REAL*8 etc?
- Next by Date: Re: bug in g95 with character arrays?
- Previous by thread: Re: bug in g95 with character arrays?
- Next by thread: Re: bug in g95 with character arrays?
- Index(es):
Relevant Pages
|