Re:C Strings and my slow descent to madness
by quelsolaar on Friday April 07, 2023 @06:32AM
(#35480140)
You know what i think about auto :-)
How is this not a quality of implementation issue? Any implementation is free to track all sizes as much as they want with the current standard.
Either a implementation is forced to issue an error at run time if there is an out of bounds read/write and in that case its a very different language than C, or its feature as-if lets any implementation ignore.
Tracking sizes for purposes of bounds checking is QoI and I think this is perfectly fine. But here we can also recover the size with sizeof, so it is also required for compliance:
https://godbolt.org/z/qh7P93Tcd
And I agree that this is a misuse of auto. I only used it here to show that the type we miss already exists inside the C compiler, we simply can name it only by constructing it again:
char (buf)[N] = ...
but we could simply allow
char (buf)[:] =
and be done (as suggested by Dennis Richtie: https://www.bell-labs.com/usr/dmr/www/vararray.pdf)
We simply can not name it without referring to N and we can also not use it in structs (ouch).