Although not very relevant to Fortran programmers, there is a new
standard available for C, called C11 (I note that C programmers haven't
learned much about the dangers of 2-digit year numbers).
This web page has some details:
http://blog.smartbear.com/software-quality/bid/173187/C11-A-New-C-Standard-Aiming-at-Safer-Programming
I like the comment (currently the last one) from David Kastrup, who said
"Fortran lovers should actually pay the C standard committee for their
work on keeping C irrelevant for serious numeric work."
--
Clive Page
|
|
0
|
|
|
|
Reply
|
usenet1820 (74)
|
6/26/2012 11:16:29 AM |
|
On 06/26/2012 01:16 PM, Clive Page wrote:
> Although not very relevant to Fortran programmers, there is a new
> standard available for C, called C11 (I note that C programmers haven't
> learned much about the dangers of 2-digit year numbers).
Actually, the ISO/ICE 9899:2011 standard has been published already half
a year ago (2011-12-08).
And for completeness, the C++ standard has also reached the level 11
last year (ISO/IEC 14882:2011; published 2011-09-01).
My impression is that C11 won't get widely used, especially given that
C99 is also not widely used.
I think the focus (in the C/C++ world) is rather on C++ and following
how C++ handles some things. (Recall that most C programs also compile
with a C++ compiler.)
Talking about standards: For Fortran, the next standard document in the
pipeline is ISO/IEC TS 29113 "Further Interoperability of Fortran with
C" (TS = Technical Specification), for which a five-month DIS ballot has
been initiated end of last month. I am actually surprised that it is a
DIS and not an FDIS ballot, though if I recall correctly ISO recently
announced that FDIS votes are optional if the DIS is approved; those
apply from 1 July and thus might or might not be a tad too late. Thus,
either by end of this year or by 2014 it will be come an official TS.
For the document itself, see
ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1917.pdf
And for completeness: The (Draft) TS refers to C99 as does the Fortran
2008 standard.
As it will take a while until the next Fortran standard or next TS will
be created, here is another standard document which relates to Fortran:
ISO/IEC TR 24772:2010 "Guidance for Avoiding Vulnerabilities through
Language Selection and Use".
That document is one of the few free-of-charge ISO documents; but I will
link to the latest draft version of revision 2:
http://grouper.ieee.org/groups/plv/DocLog/300-399/380-thru-399/22-WG23-N-0389/n0389.pdf
As the Fortran part is a bit short, here is the draft annex for
Fortran: ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1915.pdf
Happy reading,
Tobias
|
|
0
|
|
|
|
Reply
|
burnus (564)
|
6/26/2012 2:04:41 PM
|
|
On 6/26/2012 1:16 PM, Clive Page wrote:
> Although not very relevant to Fortran programmers, there is a new
> standard available for C, called C11 (I note that C programmers haven't
> learned much about the dangers of 2-digit year numbers).
>
> This web page has some details:
> http://blog.smartbear.com/software-quality/bid/173187/C11-A-New-C-Standard-Aiming-at-Safer-Programming
>
>
> I like the comment (currently the last one) from David Kastrup, who said
>
> "Fortran lovers should actually pay the C standard committee for their
> work on keeping C irrelevant for serious numeric work."
David mentions (among other things) that C now seems
to be lacking the possibility to indicate a non-aliasing
assumption for arrays.
In fortran, as we know, the non-aliasing assumption is
the default. But is there a way in fortran to exempt
a certain argument of a routine from the assumption?!
(Of course a way to force "copy in copy out" for this
particular argument would also help, but that is not
necessarily what you always want in a case like that.)
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/26/2012 6:16:39 PM
|
|
On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
> In fortran, as we know, the non-aliasing assumption is
> the default. But is there a way in fortran to exempt
> a certain argument of a routine from the assumption?!
> (Of course a way to force "copy in copy out" for this
> particular argument would also help, but that is not
> necessarily what you always want in a case like that.)
Use the POINTER and/or TARGET attributes.
|
|
0
|
|
|
|
Reply
|
ian_harvey (217)
|
6/26/2012 7:47:30 PM
|
|
Ian Harvey <ian_harvey@bigpond.com> wrote:
> On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
> > In fortran, as we know, the non-aliasing assumption is
> > the default. But is there a way in fortran to exempt
> > a certain argument of a routine from the assumption?!
> > (Of course a way to force "copy in copy out" for this
> > particular argument would also help, but that is not
> > necessarily what you always want in a case like that.)
>
> Use the POINTER and/or TARGET attributes.
Yep, allowing aliasing is a large part of what pointer is about.
As for copy-in/copy-out, that would not avoid the aliasing problem in
any event. Rather the opposite in that the possibility of
copy-in/copy-out is why aliasing is disallowed in some cases. To make
sense out of allowing aliasing in the presence of copy-in/copy-out,
you'd have to add a *LOT* more stuff. You'd have to address when the
copies happened, including what order they happened in when there were
multiple copy-outs to the same aliased location, etc., etc. No, there's
not a way in the language to do all that.
Well, actually, yes, there is a way to force copy-in/copy-out, though
I'm sure it isn't what you were thinking of because the compiler doesn't
do it behind your back. You can actually do the copy "manually" to a
separate local variable. Combine that with making the argument a pointer
so that aliasing is allowed, and you can probably get pretty
fine-grained control over how aliased arguments interact with each
other. Probably not what one would want to do in most cases, though.
P.S. I think I'll add clarification of a nit that the current posters
are probably aware of, but that some people very clearly are not. As it
stands, I'm afraid this thread might give the wrong impression.
Fortran does *NOT* have a general assumption of non-aliasing. There are
restrictions against aliasing in some cases, but not all. The details
can get picky, but the (very) short version is that aliasing is fine
until you start changing values. Yes, I have definitely seen people get
confused about that and think that aliasing was always disallowed, which
is why I thought I better correct the overly broad statement quoted
above.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
6/26/2012 8:46:53 PM
|
|
On 6/26/2012 9:47 PM, Ian Harvey wrote:
> On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
>> In fortran, as we know, the non-aliasing assumption is
>> the default. But is there a way in fortran to exempt
>> a certain argument of a routine from the assumption?!
>> (Of course a way to force "copy in copy out" for this
>> particular argument would also help, but that is not
>> necessarily what you always want in a case like that.)
>
> Use the POINTER and/or TARGET attributes.
No good solution.. That will accept only
arguments that have the pointer or target
attribute also in the calling program! It
also would block expressions like
call sub(a+b, p+q)
I want to indicate it just inside the
routine (in one place!) without shifting
any burden to the caller of the routine.
Do I really have to link to C code to get
this done?!
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/26/2012 9:27:32 PM
|
|
On 6/26/2012 9:47 PM, Ian Harvey wrote:
> On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
>> In fortran, as we know, the non-aliasing assumption is
>> the default. But is there a way in fortran to exempt
>> a certain argument of a routine from the assumption?!
>> (Of course a way to force "copy in copy out" for this
>> particular argument would also help, but that is not
>> necessarily what you always want in a case like that.)
>
> Use the POINTER and/or TARGET attributes.
No good solution.. That will accept only
arguments that have the pointer or target
attribute also in the calling program! It
also would block expressions like
call sub(a+b, result)
I want to indicate it just inside the
routine (in one place!) without shifting
any burden to the caller of the routine.
Do I really have to link to C code to get
this done?!
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/26/2012 9:31:34 PM
|
|
Jos Bergervoet <jos.bergervoet@xs4all.nl> wrote:
> On 6/26/2012 9:47 PM, Ian Harvey wrote:
> > On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
> >> In fortran, as we know, the non-aliasing assumption is
> >> the default. But is there a way in fortran to exempt
> >> a certain argument of a routine from the assumption?!
> >> (Of course a way to force "copy in copy out" for this
> >> particular argument would also help, but that is not
> >> necessarily what you always want in a case like that.)
> >
> > Use the POINTER and/or TARGET attributes.
>
> No good solution.. That will accept only
> arguments that have the pointer or target
> attribute also in the calling program! It
> also would block expressions like
> call sub(a+b, result)
Expressions are never problem with aliasing in the first place. You
can't write to a dummy argument that has an expression as an actual
argument, but that restriction has nothing to do with aliasing.
Indeed, expressions are a classic way to solve some aliasing problems.
You can sometimes do things like
call sub((x), x)
to avoid aliasing problems that would have resulted from
call sub(x,x)
I think I've lost sight of what problem it is you are trying to solve.
Perhaps that's because I don't think you ever actually stated the
problem - just what kinds of things you thought might be solutions and
what other kinds of things would not. I could try randomly guessing
solutions for a long time, but that doesn't seem like the most
straightforward way to get to a good one. As for randomly guessing
solutions, the VALUE attribute might also be on the list, but again,
until I know what the problem is, I can't tell.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
6/26/2012 9:43:49 PM
|
|
On 6/26/2012 11:43 PM, Richard Maine wrote:
> Jos Bergervoet <jos.bergervoet@xs4all.nl> wrote:
>
>> On 6/26/2012 9:47 PM, Ian Harvey wrote:
>>> On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
>>>> In fortran, as we know, the non-aliasing assumption is
>>>> the default. But is there a way in fortran to exempt
>>>> a certain argument of a routine from the assumption?!
>>>> (Of course a way to force "copy in copy out" for this
>>>> particular argument would also help, but that is not
>>>> necessarily what you always want in a case like that.)
>>>
>>> Use the POINTER and/or TARGET attributes.
>>
>> No good solution.. That will accept only
>> arguments that have the pointer or target
>> attribute also in the calling program! It
>> also would block expressions like
>> call sub(a+b, result)
>
> Expressions are never problem with aliasing in the first place. You
> can't write to a dummy argument that has an expression as an actual
> argument, but that restriction has nothing to do with aliasing.
>
> Indeed, expressions are a classic way to solve some aliasing problems.
> You can sometimes do things like
>
> call sub((x), x)
>
> to avoid aliasing problems that would have resulted from
>
> call sub(x,x)
Those problems are the problems I want to avoid.
And I do not want to rely on the caller using one
of the tricks shown above.
> I think I've lost sight of what problem it is you are trying to solve.
> Perhaps that's because I don't think you ever actually stated the
> problem
See previous paragraph. I could also say that I'm
looking for the opposite of the C "restrict", since
fortran has the opposite default assumption.
> - just what kinds of things you thought might be solutions and
> what other kinds of things would not. I could try randomly guessing
> solutions for a long time, but that doesn't seem like the most
> straightforward way to get to a good one. As for randomly guessing
> solutions, the VALUE attribute might also be on the list,
Yes, value "sounds" like the closest to the opposite
of restrict! But would it help in the example below?
> but again,
> until I know what the problem is, I can't tell.
! Example: the following routine is formally not
! correct if it is called like:
! invert(x, x)
! or
! invert( x(1:2,1:2), x(2:3,2:3) )
!
! It will usually work, but:
! Within the fortran rules the compiler is allowed
! to initialize B to zero just before the first
! statement (B = A).
subroutine invert(A, B)
real, intent(in) :: A(:,:)
real, intent(out) :: B(:,:)
B = A
! Now do the work 'in situ' using only B
...
end subroutine
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/26/2012 10:03:47 PM
|
|
"Jos Bergervoet" <jos.bergervoet@xs4all.nl> wrote in message
news:4fea31c3$0$6946$e4fe514c@news2.news.xs4all.nl...
> subroutine invert(A, B)
> real, intent(in) :: A(:,:)
> real, intent(out) :: B(:,:)
> B = A
> ! Now do the work 'in situ' using only B
> ...
> end subroutine
Yeah, giving A the VALUE attribute instead of intent(in) means
that invert gets a copy of A, not A itself, so it can't overlap
with B.
PS OT: did you hear that NCAR is under voluntary evacuation?
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
|
|
0
|
|
|
|
Reply
|
not_valid (1681)
|
6/26/2012 10:24:39 PM
|
|
Jos Bergervoet <jos.bergervoet@xs4all.nl> wrote:
> On 6/26/2012 11:43 PM, Richard Maine wrote:
> > Indeed, expressions are a classic way to solve some aliasing problems.
> > You can sometimes do things like
> >
> > call sub((x), x)
> >
> > to avoid aliasing problems that would have resulted from
> >
> > call sub(x,x)
>
> Those problems are the problems I want to avoid.
> And I do not want to rely on the caller using one
> of the tricks shown above.
>
> > I think I've lost sight of what problem it is you are trying to solve.
> > Perhaps that's because I don't think you ever actually stated the
> > problem
>
> See previous paragraph. I could also say that I'm
> looking for the opposite of the C "restrict", since
> fortran has the opposite default assumption.
I don't know C well enough to be sure of the precise definition of
"restrict", much less what its opposite would be. But...
> Yes, value "sounds" like the closest to the opposite
> of restrict! But would it help in the example below?
Yes.
> > but again,
> > until I know what the problem is, I can't tell.
>
> ! Example: the following routine is formally not
> ! correct if it is called like:
> ! invert(x, x)
> ! or
> ! invert( x(1:2,1:2), x(2:3,2:3) )
> !
> ! It will usually work, but:
> ! Within the fortran rules the compiler is allowed
> ! to initialize B to zero just before the first
> ! statement (B = A).
>
> subroutine invert(A, B)
> real, intent(in) :: A(:,:)
> real, intent(out) :: B(:,:)
>
> B = A
> ! Now do the work 'in situ' using only B
> ...
> end subroutine
Ok. Now that's something concrete I can work with.
Yes, the VALUE attribute will make that work. VALUE is a lot like making
the actual argument an expression, except that
1. You do it inside of the subroutine instead of in the call (addressing
one of your issues), and
2. You are allowed to redefine the dummy argument (with any such
redefinition not having any effect on the actyal argument). That's not
directly relevant to the case you showed.
VALUE does pretty much force copy-in (so I was half wrong in previously
stating that there was no way to force copy-in/copy-out), but copy-out
is irrelevant to value (so I'll claim that as the half that I was
right). Copy-out is a much bigger issue than copy-in in terms of
aliasing.
Of course, the essentially forced copy might have objectionable
implications on performance. It will probably end up with making 2
copies (one for the VALUE attribute, and one for the assignment
statement), plus allocating and deallocating a temporary array, where us
humans can see that doing zero copies would have had the same end
result.
Do note that VALUE is an f2003 feature, so you'll have to check detailed
compiler feature lists unless you happen to be using an f2003 compiler
(none of which exist for any platforms I currently use). It was
originally introduced for purposes of C interop, but has uses
independent of C; that's the case for several other features also
introduced with C interop as their rationale.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
6/26/2012 10:34:23 PM
|
|
On 2012-06-27 7:31 AM, Jos Bergervoet wrote:
> On 6/26/2012 9:47 PM, Ian Harvey wrote:
>> On 2012-06-27 4:16 AM, Jos Bergervoet wrote:
>>> In fortran, as we know, the non-aliasing assumption is
>>> the default. But is there a way in fortran to exempt
>>> a certain argument of a routine from the assumption?!
>>> (Of course a way to force "copy in copy out" for this
>>> particular argument would also help, but that is not
>>> necessarily what you always want in a case like that.)
>>
>> Use the POINTER and/or TARGET attributes.
>
> No good solution.. That will accept only
> arguments that have the pointer or target
> attribute also in the calling program! It
> also would block expressions like
> call sub(a+b, result)
....
Actual arguments without the TARGET attribute can be passed to dummy
arguments with the TARGET attribute.
F2008: Actual arguments without the POINTER attribute, but with the
TARGET attribute, can be passed to dummy arguments with the POINTER
attribute.
If the actual arguments are alliased in some way, and neither have the
POINTER or TARGET attributes, then how did they become aliased? If it
is because they are in turn dummy arguments in the calling procedure,
then isn't it illegal for the calling procedure to be trying to modify
them (by calling another procedure) in the first place?
|
|
0
|
|
|
|
Reply
|
ian_harvey (217)
|
6/26/2012 11:17:15 PM
|
|
Jos Bergervoet <jos.bergervoet@xs4all.nl> wrote:
(snip on aliasing)
> Those problems are the problems I want to avoid.
> And I do not want to rely on the caller using one
> of the tricks shown above.
(snip)
> subroutine invert(A, B)
> real, intent(in) :: A(:,:)
> real, intent(out) :: B(:,:)
> B = A
> ! Now do the work 'in situ' using only B
> ...
> end subroutine
All the matrix inversion routines I used to have worked in place.
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
6/26/2012 11:31:38 PM
|
|
On 6/26/12 6:31 PM, glen herrmannsfeldt wrote:
> Jos Bergervoet<jos.bergervoet@xs4all.nl> wrote:
>
> (snip on aliasing)
>
>> Those problems are the problems I want to avoid.
>> And I do not want to rely on the caller using one
>> of the tricks shown above.
>
> (snip)
>
>> subroutine invert(A, B)
>> real, intent(in) :: A(:,:)
>> real, intent(out) :: B(:,:)
>
>> B = A
>> ! Now do the work 'in situ' using only B
>> ...
>> end subroutine
>
> All the matrix inversion routines I used to have worked in place.
>
> -- glen
Do you mean they were required to work because of rules in the standard?
Or did they work with the particular arguments you used with a
particular compiler on a particular piece of hardware and a particular
choice of compiler options? How about future compilers/hardware/options?
Dick Hendrickson
|
|
0
|
|
|
|
Reply
|
dick.hendrickson (1286)
|
6/27/2012 12:35:38 AM
|
|
Dick Hendrickson <dick.hendrickson@att.net> wrote:
(snip, I wrote)
>> All the matrix inversion routines I used to have worked in place.
> Do you mean they were required to work because of rules in
> the standard?
> Or did they work with the particular arguments you used with a
> particular compiler on a particular piece of hardware and a particular
> choice of compiler options?
> How about future compilers/hardware/options?
In place, one argument for the matrix.
If it had INTENT, it would be INOUT.
As someone noted for the determinants, I remember using matrix
inversion routines in high school. I believe the one I had was
from the IBM SSP package, which is available somewhere on the net.
I don't remember ever seeing a matrix inversion routine that
didn't do it in place, though I might not have been looking
that carefully.
Also returns the determinant in case you wanted it.
-- glen
|
|
0
|
|
|
|
Reply
|
gah (12236)
|
6/27/2012 1:53:24 AM
|
|
On 6/27/2012 1:17 AM, Ian Harvey wrote:
..
> Actual arguments without the TARGET attribute can be passed to dummy
> arguments with the TARGET attribute.
>
> F2008: Actual arguments without the POINTER attribute, but with the
> TARGET attribute, can be passed to dummy arguments with the POINTER
> attribute.
>
> If the actual arguments are alliased in some way, and neither have the
> POINTER or TARGET attributes, then how did they become aliased?
Like this:
call sub( x, x )
or array slices:
call sub( x(1:n-1), x(2:n) )
where the second argument of sub() is intent(out)
> If it
> is because they are in turn dummy arguments in the calling procedure,
> then isn't it illegal for the calling procedure to be trying to modify
> them (by calling another procedure) in the first place?
subroutine proc(x)
real :: x(:)
call sub( x(1:n-1), x(2:n) )
end
You mean that the above is illegal, so even if we
can make it safe (e.g. with the VALUE attribute)
it would never be standard conforming?
I didn't think of that but you may be right..
Unless the Value attribute explicitly has the
property of lifting the general rule "no argument
shall be aliased with an intent(out) argument".
(Richard didn't address this issue in the other
post in this thread.. But I expect it is the case!)
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/27/2012 7:02:33 AM
|
|
On 6/27/2012 3:53 AM, glen herrmannsfeldt wrote:
> Dick Hendrickson <dick.hendrickson@att.net> wrote:
>
> (snip, I wrote)
>
>>> All the matrix inversion routines I used to have worked in place.
>
>> Do you mean they were required to work because of rules in
>> the standard?
>> Or did they work with the particular arguments you used with a
>> particular compiler on a particular piece of hardware and a particular
>> choice of compiler options?
>> How about future compilers/hardware/options?
>
> In place, one argument for the matrix.
> If it had INTENT, it would be INOUT.
>
> As someone noted for the determinants, I remember using matrix
> inversion routines in high school. I believe the one I had was
> from the IBM SSP package, which is available somewhere on the net.
>
> I don't remember ever seeing a matrix inversion routine that
> didn't do it in place, though I might not have been looking
> that carefully.
Strange.. I remember often seeing routines with
two arguments! (Like in the old discussion about
the CPU test of David Frank.) Example:
http://groups.google.com/group/comp.lang.fortran/msg/656639019e52c617
The routine minv() in there has seperate arguments.
> Also returns the determinant in case you wanted it.
Incidently, in the example it also gives det!
--
Jos
|
|
0
|
|
|
|
Reply
|
jos.bergervoet (38)
|
6/27/2012 7:16:32 AM
|
|
Jos Bergervoet <jos.bergervoet@xs4all.nl> wrote:
> Unless the Value attribute explicitly has the
> property of lifting the general rule "no argument
> shall be aliased with an intent(out) argument".
> (Richard didn't address this issue in the other
> post in this thread.. But I expect it is the case!)
A VALUE argument is never aliased with anything else because the
argument is an expression - never a variable. An expression can't be
aliased.
There is, alas, a bit of a terminology confusion relating to actual
arguments. There are two potentially diferent things called actual
arguments. Unfortunately, there aren't two distinct terms for them.
First, there are those things in the (standard isn't in front of me
right now, so I might slightly "misspell" some of this)
<actual-arg-list>. That list is part of the syntax and is, per the bnf
rules, a list of <actual-arg>s. In most cases, each <actual-arg> is an
actual argument, as the term might leave you to suspect. An actual
argumeng is what the dummy argument gets associated with. But in some
cases the <actual-arg> isn't the actual argument. I really dislike that
terminology confusion. The VALUE attribute triggers one of those cases.
(There are other cases as well). With the VALUE attribute, the actual
argument is not the <actual-arg> from the syntax. Instead, it is the
result of evaluating the <actual-arg> as an expression. The <actual-arg>
might be aliased to various things, but that doesn't matter because it
isn't the actual argument.
So the VALUE attribute doesn't lift that rule. The rule just never
happens to apply to a VALUE argument, so it doesn't need to be lifted.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
6/27/2012 7:19:39 AM
|
|
On 2012-06-27 5:02 PM, Jos Bergervoet wrote:
> On 6/27/2012 1:17 AM, Ian Harvey wrote:
> ..
>> Actual arguments without the TARGET attribute can be passed to dummy
>> arguments with the TARGET attribute.
>>
>> F2008: Actual arguments without the POINTER attribute, but with the
>> TARGET attribute, can be passed to dummy arguments with the POINTER
>> attribute.
>>
>> If the actual arguments are alliased in some way, and neither have the
>> POINTER or TARGET attributes, then how did they become aliased?
>
> Like this:
> call sub( x, x )
> or array slices:
> call sub( x(1:n-1), x(2:n) )
> where the second argument of sub() is intent(out)
>
>> If it
>> is because they are in turn dummy arguments in the calling procedure,
>> then isn't it illegal for the calling procedure to be trying to modify
>> them (by calling another procedure) in the first place?
>
> subroutine proc(x)
> real :: x(:)
> call sub( x(1:n-1), x(2:n) )
> end
>
> You mean that the above is illegal, so even if we
> can make it safe (e.g. with the VALUE attribute)
> it would never be standard conforming?
>
> I didn't think of that but you may be right..
> Unless the Value attribute explicitly has the
> property of lifting the general rule "no argument
> shall be aliased with an intent(out) argument".
> (Richard didn't address this issue in the other
> post in this thread.. But I expect it is the case!)
Ignore my babbling - I understand your use case. My mental picture was
that you may have wanted to modify either argument.
A tangential point, my understanding of restrict in C is that it is just
an optimisation hint to the compiler. Independent of the presence of
that keyword, the programmer can still write code that will not work as
expected (the result might be well defined, but it won't be the desired
result) if arguments are aliased. In the fortran case - I think that
using an argument with the value attribute to get around aliasing still
results in an otherwise naive implementation working.
I got up too early this morning, so I'm not really sure what point I'm
making, but I think it is something around "if you really want C like
behaviour, VALUE doesn't quite get you there - you need to be using
POINTER/TARGET etc".
In a different tangential direction, if you really want to provide the
user with both an modify in-place call option and a create new thing
call option, then don't fight the aliasing restrictions by using VALUE,
just have two specific procedures sitting behind a generic interface
with a common back-end worker procedure - one specific with one arg, the
other with two - otherwise someone will come and belt you around the
head with a big stick marked "performance loss for no good reason".
|
|
0
|
|
|
|
Reply
|
ian_harvey (217)
|
6/27/2012 8:34:13 AM
|
|
|
18 Replies
42 Views
(page loaded in 0.516 seconds)
Similiar Articles: Unsigned Integer Overflow on Multiplication and Division - comp ...Work is in progress on a new ISO C standard that will supersede C99, currently referred to as C201X; the latest draft I'm aware of is n1425.pdf, available from the same ... truncate file - comp.lang.c++.moderatedI know the boost::filesystem library was formed to a proposal for the new standard. ... chain that can detect the specific operating system, and check for the available ... Checking for whether compiler supports C99 or C++0x - comp.lang ...When C++0x becomes final there will be a new standard ... features likely to be included in C++0x are available. ... Since the C standard requires the compiler to be able to ... Accession Number - comp.protocols.dicomI'm new to DICOM. What's the purpose of the Accession Number? Is it ... You may look up the specific data object in Part 3 of the DICOM Standard available at http ... vec3 and vec 4 C++ class - comp.graphics.api.opengl... class mimicking the features available in the vec3 and vec4 objects defined by the GLSL standard? ... rotate my new vector using vec3 new ... angle); float u = 1 - c ... does vector::resize throw bad_alloc exception? - comp.lang.c++ ...An exception could be thrown but Standard ... 2/6 - void resize(size_type sz, T c ... that will rely on: void* operator new(size_t) throw(bad_alloc) so in case of available ... Delay in C on linux or OSS - comp.lang.cThe select() and poll() calls (if available) can be ... There isn't any portable way to do this in standard C. ... Hi I am new to ... on Linux - Stack Overflow I would ... Stacks Queues and other data structures. - comp.lang.pascal.misc ...... with what's available in the FCL ... separate types because new cannot use an arbitrary size (and still adhere to standards). This will be the major logical change from C ... one producer thread, one consumer thread: mutex needed? - comp ...In standard C, neither "pipe" nor "mutex" have any meaning. ... For example, it will ensure that the size of the available ... does: queue.lower(); // block until at least one new ... Help to choose a new MCU - comp.arch.embedded... Quadrature encoder interface - One standard PWM ... but I can live without it > - I/O > 40 > - C programming tools available ... Luminary micro is completely new for me. I ... ieee_ proposed library - comp.arch.fpgaNow introduce your proposed new indexing ... conventionally used for macros (no, the standard library ... point in base C ... from the IEEE ... much any computer available ... Where did Fortran go? - comp.lang.fortran> > I think Fortran 2003 compilers are more available than C++ 03 compilers. ... I wonder how much of new newer code is really (ISO-standard) Fortran 77 and how much is Fortran ... GNU-awk bug in sub()/gsub() - comp.lang.awko.i.c, it seems they don't agree with the standard. ... either of the other two freely available ... The new standard is fairly recent and I haven ... routing to two subnets over the same interface - comp.unix.solaris ...... 255 Netmask: 255.255.255.0 Easy enough; its a standard /24 (class C) network. Its with the new ... of classless addressing the points where networks are available ... Any RFC for NTPv4 ? - comp.protocols.time.ntp... formal specification of this version is not yet available. ... NTPv3 specification rfc-1305 never reached full standard ... was certainly the case back when Multicast was new ... C++11 - Wikipedia, the free encyclopediaPrefer introduction of new features through the standard library, rather ... The C standard library provides the ability to ... Text is available under the Creative Commons ... C99 - Wikipedia, the free encyclopediaNormative Amendment 1 created a new standard for C in 1995, but only to correct some ... Text is available under the Creative Commons Attribution-ShareAlike License ... 7/19/2012 9:47:49 PM
|