I will soon start using C for a course in operating systems, and I read about the best practices for using C to reduce headaches later.
These were always my first questions regarding arrays, as they are easy to screw in.
Is it common practice to bind an array and its associated variable containing its length in the structure?
I have never seen it in books, and usually they always keep two separate or use something like sizeof (array [] / array [1]).
But by wrapping them in a structure, you can pass the structure both by value and by reference, which you cannot really do with arrays unless you use pointers, in which case you need to track the length of the array again.
I am starting to use C, so the above can be terribly wrong, I'm still a student.
Cheers, Kai.
source
share