[C] determining size of an array in a function

From: Marlene Stebbins (stebbins_at_email.com)
Date: 06/25/04


Date: Thu, 24 Jun 2004 22:57:34 GMT

My program performs several statistical tests on a list of
numbers. For example:

double stdev(double *arglist, int listsize); /* prototype */
double data[] = {76.9, 45.5, 32, 99.6, 12, 56.2, 79.9, 81};
int listsize = sizeof(data) / sizeof(*data);
double s = stdev(data, listsize);

The function needs to know the size of the array, so I am passing
it as an argument. I am wondering if there is any way for the
size of the the array to be determined in the function -- without
  a global variable or a kludge -- so I can eliminate the 2nd
argument in the call to stdev(). I think there is no elegant way
to do this, but I thought I would ask the experts.

Marlene



Relevant Pages

  • Re: [C] determining size of an array in a function
    ... > The function needs to know the size of the array, ... the function only receives a pointer to the array's ... and you can't determine the size of the array from that. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C] determining size of an array in a function
    ... Marlene Stebbins wrote: ... > My program performs several statistical tests on a list of numbers. ... > The function needs to know the size of the array, so I am passing it as ... double stdev(double *arglist, int listsize); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C] determining size of an array in a function
    ... > The function needs to know the size of the array, ... It may be possible to terminate the array with a value ... then you might be able to terminate the array with that value. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C] determining size of an array in a function
    ... > The function needs to know the size of the array, ... pointer, and the pointer doesn't contain any information ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Write a function thats not in its own m-file
    ... This function needs to return an array of values. ... I looked through the MATLAB documentation regarding Anonymous Functions and I couldn't find anything about returning multiple values / array of values. ...
    (comp.soft-sys.matlab)