Is it worth declaring function arguments as const when appropriate?
For example, suppose I'm trying to find the maximum value of an array & the indices at which it occurs.. a prototype might look like:
int max(double *array, int length, double *max, int *indices)
array and length will not be changed; is it useful to declare these as const? Would I do it like this:
int max(double const *const array, int const length, double *max, int *indices)
i.e. array is a constant pointer to constant data and length is a constant integer.
Also, if for some reason I wanted length passed by reference, would I write: int const *length? So length is a pointer to constant data. Or should I write int const *const length? i.e. length is a constant pointer to constant data.
-Eric
For example, suppose I'm trying to find the maximum value of an array & the indices at which it occurs.. a prototype might look like:
int max(double *array, int length, double *max, int *indices)
array and length will not be changed; is it useful to declare these as const? Would I do it like this:
int max(double const *const array, int const length, double *max, int *indices)
i.e. array is a constant pointer to constant data and length is a constant integer.
Also, if for some reason I wanted length passed by reference, would I write: int const *length? So length is a pointer to constant data. Or should I write int const *const length? i.e. length is a constant pointer to constant data.
-Eric
