store it in the bytes before the start of the array. Maybe use a bit flag to indicate additional bytes if length is too much to store in one byte. Like unicode
I was thinking for statically defined arrays, not for file streams or dynamic memory allocation
Do you know that, for statically defined arrays, you can get the size like this:
int foo[10];
int ten = sizeof(foo)/sizeof(foo[0]);
Of course, that doesn’t work if you do that with a function argument because you can’t pass arrays as arguments, only pointers, so a function can’t know whether a passed value is a statically defined array or dynamically allocated.
int f(int * foo) {
return sizeof(foo)/sizeof(foo[0]); //
}
int notTen = f(foo);
4 comments
[ 0.26 ms ] story [ 15.6 ms ] threadHow often to assure it is still correct?
What about dynamic streams?
Do you dream it will prevent stack overflow or out of bounds access?
I was thinking for statically defined arrays, not for file streams or dynamic memory allocation
Ah, Pascal strings. There is a reason why they have lost the battle.