3 ms·
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
by hnaccountme 2y ago
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
- Someone 2y agoDo 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); That even is the case when you do things like these (https://stackoverflow.com/a/2375038 https://stackoverflow.com/a/2375038): int f(int foo[10]) { return sizeof(foo)/sizeof(foo[0]); } int notTen = f(foo); or int f(int foo[static 10]) { return sizeof(foo)/sizeof(foo[0]); } int notTen = f(foo);
- eimrine 2y ago> store it in the bytes before the start of the array Ah, Pascal strings. There is a reason why they have lost the battle.