sizeof and array parameters

Taso Hatzi taso at munnari.OZ
Fri Dec 28 23:33:57 AEST 1984


In article <6794 at brl-tgr.ARPA> Craig Partridge <craig at loki.ARPA> writes:


>
>#define ARRAYSIZE 4
>
>readarray(fd,a)
>int fd;
>int a[ARRAYSIZE];
>{
>    read(fd,a,sizeof(a));
>}
>

Might I suggest that what you really meant was:

#define ARRAYSIZE 4

readarray(fd, a)
int fd;
int (*a)[ARRAYSIZE];
{
    read(fd, a, sizeof(*a));
}


You should find the last two paragraphs of K & R p94 informative. 

I think it's unfortunate that 

f(x)            
int x[N];
{
}

is a legitimate way of declaring an array argument. It has made it practically
impossible to allow for arrays to be passed by value. On the other hand, given
that arrays will never be passed by value, it does make array references from
inside the function look tidier.



More information about the Comp.lang.c mailing list