Message from discussion Function returning defined type?
Received: by 10.216.199.78 with SMTP id w56mr1531794wen.11.1351391169461;
Sat, 27 Oct 2012 19:26:09 -0700 (PDT)
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Subject: Re: Function returning defined type?
Date: Mon, 22 Oct 2012 05:12:00 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com>
User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.32-5-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.8.2
jski <john.chludzin...@gmail.com> wrote:
(snip regarding indexing, substringing, function calling and
member selection on the return value of a function.)
> At the risked of being flamed, without simply saying Fortran isn't C,
> is there a rationale for:
> if F(x) returns a type with components a, b, and c, why is F(x)
> %c a "syntax error"?
As mentioned in another post, there are some ambiguous cases, even if
this isn't one. One that I miss more is arrays of pointers, which
are also not allowed, possibly because of the ambiguities.
> PS> Actually, in the case of the C++ I'm translating, it turns out
> the function call I'm referring to here is the indexing into an STL
> map<>. This is done over 2 dozen times in a loop the iterates at
> least 1 million times per run. Replacing these index "calls" is an
> obvious step to improving its performance.
Are you claiming that the Fortran syntax is slower because it
requires an explicit temporary variable?
It might be that the C or C++ compilers generate a temporary
anyway, and it might be that the Fortran compiler can
optimize out the store into the variable. It is a syntax
question, not a performance question. Besides, it might
take one extra instruction, and so your 12 million calls
might take a few milliseconds longer.
Now, note that returning a structure requires the function
to return all the elements of the structure, though
you only need one. (Well, possilby there is only one member.)
Same for arrays. Indexing a function returning an array is a
waste, unless the array only has one element.
If performance is a question, write a version of the function
that returns only that element. (Or an ENTRY point into the