Passing an Array as a Pointer

2000-11-13
2000-11-13
  • When an array is passed to a function, and it is defined as a pointer in the function declaration, then the function has no way of knowing how many elements are in the array.  Should the number of array elements be passed as a separate parameter?  Sometimes?  Never?  Always?

    Example:  In the first draft of the implementation of STRING (cobr_string.c), the number of delimiters and the number of items they pertain to, could theoretically exceed the actual number of items available.  In such a case, an attempt would be made to pull a value from beyond the end of the array.  This is prevented, of course, in the process of parsing, but it is theoretically possible.   Is this something that should be checked within the function?