extern char *foo vs. extern char foo[]

Paul Nulsen pejn at wolfen.cc.uow.oz
Wed Jun 6 10:59:16 AEST 1990


In article <16788 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>
>Actually, function arguments in C are *always* passed by value ...
>
>In the case of an array, strictly speaking, a true call by reference in this
>sense would be `void f(int (*pa)[N]); ... f(&a);', where the user explicitly
>passes the address of the array (and the caller expects it)...

My argument is not that there is internal inconsistency in the treatment of
arrays by C. The inconsistency is between the treatment of arrays and other
types. If the syntax of C was entirely consistent an `a' in a
function argument would push the entire array onto the stack. For example,
	int a[10];
	printf ("%d\n", sizeof(a));
produces 10 * sizeof(int). For any other type (including struct's) the thing
pushed onto the stack is the value of the entire entity, using a space equal
to sizeof (entity). This is not meant to be a criticism of C, just an
observation about the source of confusion.

You have produced yet another illustration of the confusion caused by the
handling of arrays. C compilers will ignore the & in f(&a). This is because,
within the scope of the array definition, there is no data location where
the address of a is kept. If the compiler was pedantic (and did not concede
some inconsistency) it should reject this as a syntax error.



More information about the Comp.lang.c mailing list