JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2000

COMP-FORTRAN-90 2000

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Bug or feature - revisited

From:

Friedrich Hertweck <[log in to unmask]>

Reply-To:

Friedrich Hertweck <[log in to unmask]>

Date:

Thu, 29 Jun 2000 11:46:37 +0200

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (195 lines)

Malcolm Cohen schrieb:

> Friedrich Hertweck said:
> >William F Mitchell schrieb:
> >>With intent(in) the compiler can assume the argument will not be changed.
> >>If the user overrules it as you suggest, then the program is not standard
> >>conforming.
> >
> >I have not found any rule that prohibits this.  In a pointer assignment
> >definition there is no constraint to that effect
>
> Programs must obey all rules in the standard, not just the constraints.

I agree with that.

> The only thing special about the constraints is that the compiler is
> required to diagnose their violation.

Are you saying that a compiler is NOT required to diagnose the violation of
a rule? I must say that I have difficulties understanding Sec. 1.5 (Conformance).
My naive assumption is that all rule violations should be diagnosed.
Maybe I am wrong here.

> 5.1.2.3 states
> "The INTENT(IN) attribute specifies that the dummy argument shall neither be
>  defined nor become undefined during the execution of the procedure."
>
> i.e. no matter with how much trickery you hide the fact from the compiler,
> you just are not allowed to alter the value of INTENT(IN) dummy arguments
> during that procedure's execution.  But the compiler need not complain - it
> can start WW3 instead.

What is WW3?

> [...]
> >As far as I can see, the production of undefined pointers is
> >standard-conforming,
>
> Yes indeed it is; but all you can do with them is pointer-assign them to
> other pointers, you are not allowed to reference or deallocate them.
>
> ...again, the compiler need not diagnose any error you make.
>
> >It is not only the interface: the function result is a pointer-assignment.
> >A function like that does NOT make sense if it returns an undefined pointer.
>
> It might not make sense to you (or indeed to me), but pointer functions are
> perfectly entitled to return undefined pointers.  It is up to the user not
> to do anything harmful with them.
>
> >Here is an improved
> >version of the function RES2 which will NOT accept the result of the RESHAPE:
> >
> >     function ptr(a,n1,n2)
> >        integer, pointer :: ptr(:,:)
> >        integer :: n1, n2
> >        integer, target, INTENT(INOUT) :: a(n1,n2)
> >
> >        ptr => a
> >     end function
> >
> >The INTENT(INOUT) makes sure that the actual argument   a(n1,n2)   cannot be
> >an expression (or, which is basically the same, an indexed array section).
>
> No it does not.  It does make sure it cannot be an expression, but an
> array section is perfectly acceptable; the compiler will almost
> certainly generate a copy-in copy-out in this case (which will result
> in "ptr" being unusable).

At least three compilers do NOT accept indexed array sections
(among them also NAG F95):

DEC Visual F95:
--------------------
prog.f90(16) : Error: An array section having a vector subscript is not permitted
if
               dummy argument has intent [IN]OUT   [X1]
   p2 => ptr(x1(z),n,n)
-------------^

IBM F95:
-----------
"prog.f90", line 16.14: 1516-056 (S) An accessible explicit interface has a
            dummy argument with the INTENT(OUT) or INTENT(INOUT) attribute
specified.
            Corresponding actual argument which is not definable is not permitted
            in this context.

NAG F95:
------------
Error: prog.f90, line 16: Argument A (no. 1) of PTR is OUT or INOUT but is not a
variable

> >When the actual argument corresponding to  a(n1,n2)  does not have the TARGET
> >attribute, the function permits a pointer to be assigned to a non-target
> >object, which moreover violates the rule that a pointer shall only be
> >assigned to a target of  the same type,
> >kind type parameters, and rank (sec. 7.5.2  -  Pointer assignment).
>
> >I do not feel uncomfortable with this situation
>
> I agree - this is not very nice at all.
>
> >So I maintain my position that a good compiler should be able to check on
> >these things.
>
> This would certainly be nice; I don't know of any that do as yet - we've
> added quite a few inter-procedural checks recently but we don't yet spot
> these particular problems with pointers.
>
> The problem here is that the standard wording is vague:  the facility is
> >supposed to be PROCESSOR DEPENDENT, so the user must check it.
>
> Hmm, I think that the problems here are such that a user is not meant to
> use it.

While you (Malcolm Cohen)  argue from the standpoint of compiler vendors,
I try to argue from the standpoint of the user: is it legitimate to ask for
a data structure to be viewed in different ways? I believe it is.
(Van Snyder said that in his case to copy the data, because of its size,
would not be feasible.) There is of cause one old way to do it in Fortran
(Fortran 77): by using EQUIVALENCE, probably with data in a COMMON
block. So the facility was (is) there; but this to use a pointer would probably
be a better way to describe it; one should avoid COMMON in modern Fortran
(and EQUIVALENCE anyway).

> The processor dependency is not necessarily checkable (it may
> vary unpredictably - the user cannot rely on a check in one instance
> meaning that it will work in future calls).

This now is an issue of product stability. If you have a (supposedly well
documented) feature in a compiler that is declared ba the standard as
"processor dependent", a user might well use it and invest quite a bit of
programming effort. It will be hard for him if the manufacture just takes it away.

(Was that not a reason to have all of F77 in F90?)

> With a sufficiently checking compiler, your program would cease to work
> because of the undefined pointer.

True.
But because I argue goal-oriented I would like to have a more modern
facility that would resolve Van Snyders problem. Technically, there
are no diffculties:
In this particular case what happens with pointer assignment is obvious;
for this reason all systems behave alike, and also reasonably. (The address
of the data object and its shape are placed into the pointer data structure
and returned by the function. You can easily check that when you print
the contents of the pointer data structure. Yes, you can do it in Fortran.)
That is what MUST happen as long as the pointer inside the function is valid;
the problem only arises when the procedure terminates: the STATUS
of the pointer becomes undefined, but the information is still there.

> With a sufficiently optimising compiler, your program would give the
> result you expect but more complicated "real" programs would give
> results you would not expect because of the unexpected (and invalid)
> aliasing you have set up.

I fail to see what this has to do with optimization: I would require from
an optimizing compiler NEVER to change the semantics of a program
(things like arbitrary order of evaluation, etc. are covered by the standard).
There are some examples where this is done (IBM -O3 has that property;
though they sometimes issue a warning, I never use this level, only -O2).
Reliability is first, speed is second, in my opinion.
(Everybody knows the frustration when an optimized program fails,
but the -g version works perfectly well.)
What I am willing to accept is that a compiler with more thorough analyzing
would issue a WARNING that the pointer returned by the function has undefined
status.
Another way would be to have an additional intrinsic pointer procedure
(permitted by the standard) like:
      RESTRUCTURE(arr,shape)
where arr is an array of any rank (with the target attribute), and shape a
rank-1 array with the shape of the result. With p defined as an array with
the pointer attribute,  say:   <type of x1>, pointer :: p(:,:),  the statement
      p => RESTRUCTURE(x1, (/ n1, n2 /))
would do what is required, provided  SUM(shape)==SIZE(arr).
It would be in the interest of the users if vendors could agree on that.

> My summary: just don't do this folks.  It's too complicated, you'll
> probably shoot yourselves in the foot.

I do not agree that it is too complicated, in my opinion it is very simple
and straightforward. Instead of "shooting ourselves in the foot" we need
another solution than going back to Fortran 77 or (forward?) to C
(where these things are done all the time - but on a lower level because
you actually can use addresses of object directly).

Regards,
Friedrich



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager