Re: A doubly linked-list in C



Kaz Kylheku wrote:
Both views are simultaneously correct.

I agree. I think both views are reconciled by the technical distinction
between "pass *by* reference" and "pass *a* reference".

C never passes *by* reference (always *by* value). Yet in C you can pass
*a* reference.

It appears that the standard has been crafted with that distinction
("provides *a* reference" from what you cited).

It's also a distinction that appears in what I believe to be one of the
best programming-language texts around, _Programming Language Pragmatics_,
2nd edition, by Michael L. Scott.

On pg. 419, we see "Parameters in C are always passed by value, though the
effect for arrays is unusual: because of the interoperability of arrays
and pointers in C (Section 7.7.1), what is passed by value is a pointer;
changes to array elements accessed through this pointer are visible to the
caller."

(Scott uses the "actual parameter" vs. "formal parameter" terminology.
"Pass by value" and "pass by reference" are "parameter modes".)

On pg. 421, we see "One traditional problem with parameter modes---and
with the READONLY mode in particular---is that they tend to confuse the
key pragmatic issue (does the implementation pass a value or a reference?)
with two semantic issues: is the callee allowed to change the formal
parameter and, if so, will the changes be reflected in the actual
parameter? C keeps the pragmatic issue separate, by forcing the programmer
to pass references explicitly with pointers."

Yours,
Han from China

--
"Only entropy comes easy." -- Anton Chekhov

.



Relevant Pages

  • Re: Array comparison
    ... > Deep and recursive. ... the pointers and comparing their referents instead of comparing the ... >> arrays, then I think you also need to argue against assigning arrays. ... semantics (notably, reference counting). ...
    (alt.comp.lang.borland-delphi)
  • Re: Fortran and .NET (C#)
    ... Was there "garbage collection" in Fortran 90 or was there reference counting? ... For functions returning arrays that are either explicit-sized or allocatable, the language is designed such that you don't need either of those. ... And if one is a novice, well, one pretty much abandons all hope of a bug-free program if one uses functions that return pointers. ... Recall that, unlike C, Fortran doesn't force you into using pointers just because you have arrays. ...
    (comp.lang.fortran)
  • Re: arrays
    ... Basically: String literals are pointers. ... I appreciate that arrays and pointers are different, ... understood /why/ we make that distinction, other than in 3 specific cases. ...
    (comp.lang.c)
  • Re: Fortran and .NET (C#)
    ... >> I seem to remember Fortran 90 allowing arrays to be returned by ... No reference counts or garbage collection is needed. ... Is it true that memory that a Fortran pointer "points" to may not be ... > Recall that, unlike C, Fortran doesn't force you into using pointers just ...
    (comp.lang.fortran)
  • Re: about reference
    ... In ANSI C a pointer is an address into raw memory. ... Static arrays are implemented as pointers that cannot be ... In Perl the reference is a address of an entry in the symbol table. ...
    (perl.beginners)