Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site watdaisy.UUCP
Path: utzoo!watmath!watdaisy!ndiamond
From: ndiamond@watdaisy.UUCP (Norman Diamond)
Newsgroups: net.lang
Subject: Re: Constants in subroutine calls
Message-ID: <6853@watdaisy.UUCP>
Date: Sun, 13-Jan-85 14:56:20 EST
Article-I.D.: watdaisy.6853
Posted: Sun Jan 13 14:56:20 1985
Date-Received: Fri, 18-Jan-85 15:29:45 EST
References: <6599@brl-tgr.ARPA> <979@opus.UUCP>
Organization: U of Waterloo, Ontario
Lines: 47

>       SUBROUTINE A(R)         !PRINT THE PRODUCT OF R AND (R+1), RETURN R+1
>       TEMP=R
>       CALL SUCC(R)
>       PRINT *,TEMP*R
>       RETURN
>       END
> 
>       SUBROUTINE SUCC(R)      !RETURN SUCCESSOR OF R
>       R=R+1
>       RETURN
>       END
> 
> Subroutine A will work correctly on the CRAY, even when its argument is a
> constant.  The 'error' doesn't propagate back up to the calling routine,
> since only a copy of the constant was altered.  (This is an admittedly
> contrived example, but it does demonstrate the point.  I have used this
> technique to advantage before - it eliminates the need to use dummy variables
> to pass constant values to subroutines when I don't care about the returned
> value.  I always carefully flag this trick as being non-standard.)
> 
> The CRAY compiler is standard conforming too, since the standard doesn't
> require non-conforming code to be reported or corrected.  The standard only
> requires that conforming programs be executed correctly.
> 
> 
>                                               James Giles

Yes, the CRAY compiler conforms to the standard.  Your program does not conform
to the standard.

A compiler can do whatever it wishes in cases that do not have to be reported
or corrected.  A compiler can implement dozens of extensions, and technically
just be required to report when the extensions are used.  A program that uses
such extensions is a non-conforming program, and no one should compilain when
it doesn't port very easily.

About subroutine A working "correctly", Mr. Giles meant that subrouting A does
what he wants it to do.  Lots of other possibilities would also be correct, as
far as the standard is concerned.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy@waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."