Re: character*1(28) and character*28
- From: Googleer <stocksami@xxxxxxxxxxxxx>
- Date: Mon, 25 Jun 2007 15:54:41 -0700
On Jun 25, 3:00 pm, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
Lynn McGuire <nos...@xxxxxxxxxx> wrote:
Is there any difference between character*1(28) and character*28 ?
Yes. A huge difference. One is a character string. The other is an
array. I couldn't detail all the many differences that result from this
- there are far too many of them.
If I declare a variable character*28, data it as 'some long string', and
call a subroutine with the arg list declared to be character*1(*), is all OK ?
character*28 astr
data astr / 'some long string' /
call sub1 (astr)
subroutine sub1 (astr)
implicit none
character*1(*) astr
That particular case is ok by a special exception to the argument
passing rules. It did require a special exception. In fact, it is so
special that it applies only to default character kind (and, in f2003,
to the C character kind). Odds are that your compiler doesn't support
any character kinds other than default, so that's a bit of a side point.
I make the side point only to illustrate how special that particular
rule is. Do *NOT* try to generalize the principle to other situations,
because you'll draw the wrong conclusion. This case is an exception to
the usual rules, not an example of the usual rules.
Note, by the way, that your dmmy argument is an assumed-size array. That
has lots of consequences. Mostly the compiler does not know how long it
is. It does *NOT* pick up the dummy array size from the actual argument
length. The * in a dummy argument means different things for a character
string and an array. For a character string, it means assumed length,
which picks up the length from the actual argument. For an array, it
means assumed size, which does not pick up a size from the actual. (And
it is possible to have both at the same time with an assumed-size array
of assumed length string).
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Is that legal code? It doesn't compile in AIX. I accidently typed
code like that recently and it wouldn't compile.
.
- Follow-Ups:
- Re: character*1(28) and character*28
- From: Richard Maine
- Re: character*1(28) and character*28
- References:
- character*1(28) and character*28
- From: Lynn McGuire
- Re: character*1(28) and character*28
- From: Richard Maine
- character*1(28) and character*28
- Prev by Date: Re: Does F2003 has the similar fuction like "template" in C++??
- Next by Date: copying character strings to smaller string
- Previous by thread: Re: character*1(28) and character*28
- Next by thread: Re: character*1(28) and character*28
- Index(es):
Relevant Pages
|