Re: arrays as function arguments
- From: Ioannis Vranos <ivranos@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Feb 2008 01:03:12 +0200
fkater@xxxxxxxxxxxxxx wrote:
Hi,
why doesn't calling f1 (see below) cause a warning while calling f2
does? Both seem to pass the wrong type. Is there another way to
declare f1 so that the caller is forced (warned) if the passed array
hasn't the same elements? I hope this is related to C and not a
question of the used compiler (here: gcc-4.1.2).
void f1(int a[4]){}
void f2(int (*b)[4]){}
int main(int argc,char** argv){
int c[4+1];
int (*d)[4+1];
f1(c); /* no warning */
f2(d); /* warning: incompatible pointer type */
return 0;
}
Felix
In C, array arguments are equivalent to pointers, so for example:
void somefunc(char array[10])
{}
void somefunc(char array[])
{}
void somefunc(char array[5])
{}
void somefunc(char *array)
{}
are all equivalent.
.
- References:
- arrays as function arguments
- From: fkater@xxxxxxxxxxxxxx
- arrays as function arguments
- Prev by Date: arrays as function arguments
- Next by Date: Re: Using exact-size structs to go thru raw byte buffers
- Previous by thread: arrays as function arguments
- Next by thread: Re: arrays as function arguments
- Index(es):
Relevant Pages
|