> From: Richard A. Smith [mailto:[EMAIL PROTECTED]]
> 
> On Mon, 18 Oct 1999 12:16:32 +0100, Mathew Hendry wrote:
> 
> >int
> >sum_array_ar(int *array, long len) {
>
> I just noticed that you pass array into the function in pointer
> notation but then use it as an array inside the funtion.  I have a C
> purist friend who claims that this is bad and has test cases where
> this can cause problems.  Although I can't remember what they were.
> (I will forward it to him and ask and post the results)  I think it
> has to do with multi-diminsional arrays.

Yes. For an n-dimensional array, you need to know (at least) the last n-1
dimensions to be able to index it properly. So, for a 3-D array, you would
need at least

  int func(int data[][YDIM][ZDIM]);

but

  int func(int data[XDIM][YDIM][ZDIM]);

would work just as well.
 
> IIRC he claims that the proper function definition should be:
> 
> sum_array_ar(int array[SIZE], long len) {

As far as C is concerned

  void func(int *a);
  void func(int a[]);
  void func(int a[1024]);

are equivalent. Try it with "gcc -W -Wall -ansi -pedantic" - not a whisper.
Lint might complain, though...

-- Mat.
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to