Pascal question... really C extension (longish)
Chris Shaw
cdshaw at watmum.UUCP
Fri Apr 19 02:52:08 AEST 1985
[]
>In article <> jack at boring.UUCP (Jack Jansen) writes:
>>
>>function p(var i:integer):integer;
>> ^^^
>>begin
>> p := i;
>> i := i+1;
>>end (* p *);
>>
>
>The 'var' keyword has the effect that the value of 'i' is assigned
>to the corresponding actual parameter in the calling routine at the
>termination of the called routine.
>--
>Ken Montgomery "Shredder-of-hapless-smurfs"
Well... not really. Ken's response implies copy-in copy-out semantics
(the value of "i" is copied into the function on entry, & copied back on exit).
Pascal never uses copy-in/out, but instead uses call-by-reference.. that is,
a pointer to "i" is passed to the function p, and the function varies the
actual parameter of the calling routine.
i.e.
program blortorama ;
var x, y : integer ;
begin
y := p( x ) ;
end.
Will pass a pointer to x, and the function p will play with the value of x
directly. Note that in C this looks as follows:
main()
{
int x , y ;
p( &x );
}
p( i )
int *i ;
{
i++ ;
return( *i -1 );
}
(Please ignore the weird business in p.. I wanted to make sure the actions
were the same.)
The reason why I'm saying all this is to show the ease of translation from
call-by-reference to call-by-value. Thus the people at Lawrence Livermore
(I think) who want to make C call-by-ref. for Crays are really wasting their
time by wanting to redefine the language. The functionality is there for
call-by-reference, although hidden slightly.
Their motivations are obvious, however. The C translation of the Pascal program
is clumsy because of all the extra symbiology, and the confusion people have
about things like operator precedence when the * operator is used.
If the language extension proposed by LL Labs is such that it can be easily
translated to "real" C, (say thru typedefs or something), then more power to
them, because a neat implementation of call-by-ref. would be nice. A true
redefinition of the language is to be avoided, however.
More information about the Comp.lang.c
mailing list