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?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ron Shepard  
View profile  
 More options Oct 21 2012, 2:31 am
Newsgroups: comp.lang.fortran
From: Ron Shepard <ron-shep...@NOSPAM.comcast.net>
Date: Sun, 21 Oct 2012 01:31:14 -0500
Local: Sun, Oct 21 2012 2:31 am
Subject: Re: Function returning defined type?
In article
<91b30443-7f8c-490f-8d4d-a076d4996...@b6g2000yqd.googlegroups.com>,

 jski <john.chludzin...@gmail.com> wrote:
> On Oct 21, 1:02 am, jski <john.chludzin...@gmail.com> wrote:
> > On Oct 20, 5:00 am, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:

> > > john.chludzin...@gmail.com wrote:

> > > (snip)

> > > > type(hash_tbl_sll) :: table
> > > > ...
> > > > call table%put(1, Coords(1, 2, 3))
> > > > print*, table%get(1)%x
> > > > This results in:
> > > > $ gfortran HashTbl.f95
> > > > HashTbl.f95:173.22:
> > > >  print*, table%get(1)%x
> > > >                      1
> > > > Error: Syntax error in PRINT statement at (1)
> > > > This may be too C/C++'esque but the returned value is type(Coords),
> > > > shouldn't I be able to reference a member?

> > > Yes, Fortran isn't C or C++. In C, [], (), and . are operators,
> > > but they aren't in Fortran.

> > > You can't subscript (asked reasonably often), call, substring,
> > > or select structure members from the return value of a function.

> > > -- glen

> > Hmmmm ... think I'll charge "get" back into a subroutine.

> > BTW, into what category in Fortran does "%" fall?

> > ---John

> ... think I'll CHANGE "get" back into a subroutine.

The other good reason for doing this is when the function is used in
a print or write statement (as you were trying to do), then you can
then not do any i/o within the function (e.g. for debugging, for
printing error messages, or anything).  This is called "recursive"
i/o, and it is not allowed at all up through f95, and only in some
restricted situations in the newer standards.  So it is better to
just avoid the problem in the first place by using a subroutine
rather than a function.

$.02 -Ron Shepard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.