Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
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)
MIME-Version: 1.0
Path: q13ni70624wii.0!nntp.google.com!feeder3.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!xlned.com!feeder1.xlned.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!aioe.org!.POSTED!not-for-mail
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Newsgroups: comp.lang.fortran
Subject: Re: Function returning defined type?
Date: Mon, 22 Oct 2012 05:12:00 +0000 (UTC)
Organization: Aioe.org NNTP Server
Lines: 43
Message-ID: <k62kj0$1hh$1@speranza.aioe.org>
References: <92e0dca8-9495-41a3-beed-9d413715464d@googlegroups.com> <k5tp80$49o$1@speranza.aioe.org> <c49317df-416f-498c-8885-69e9329a39f0@o8g2000yqh.googlegroups.com> <c343a3b1-9f88-4325-9a63-e6dbdd3ce16e@googlegroups.com> <4ef7e682-013d-420a-a7b2-2c456fb398e5@g8g2000yqp.googlegroups.com>
NNTP-Posting-Host: iv0FLp+Uhvv05NzXKWDP0Q.user.speranza.aioe.org
X-Complaints-To: abuse@aioe.org
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
Bytes: 2713

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
existing function.)

-- glen