5 ms·
> But then I can't use sizeof() if I pass that buffer into a function via a pointer. Obviously, this isn't necessarily an improvement, but in theory you could
by tpoacher 4y ago
> But then I can't use sizeof() if I pass that buffer into a function via a pointer.
Obviously, this isn't necessarily an improvement, but in theory you could do this:
size_t getlength( int m, char (*p) [m] ) { return sizeof *p; }
where you'd be calling it like this:
char mystring[] = "Hello";
getlength( sizeof mystring, &mystring )
But then you're back in "having to pass the length as a separate parameter" territory, I guess. (but at least it's the length of the array here, not just the zero-terminated component, which is what you wanted).