I (think I) understand that you can only retrieve the size of an array (using sizeof) if it is declared at compile time on the stack, e.g.
int my_array[] = {1,2,3};
sizeof(my_array) == 3;
As soon as you start using pointers you lose this length information.
e.g. if you pass a pointer to int as a function parameter to get an int array into a function you can no longer use sizeof()
in this way, it will just return the number of bytes used to store a pointer.
Clearly, it is vital to know how long your arrays are.
So which of the following options should I use when passing arrays around?
Pass a pointer and an accompanying length parameter
int my_func(int *my_array, size_t len_my_array)
Create my own vector struct
struct vector { int *my_array; size_t len; } int my_func(struct vector *my_vector)
Use someone elses vector implementation. (Is there a default implementation for C as there is for C++?)
Another approach which I've missed?
(I'm currently using the 1st option but its a bit unwieldy and I'm keen to know if this is considered poor programming practice)