[TUHS] Minimum Array Sizes in 16 bit C (was Maximum)
Anton Shepelev
anton.txt at gmail.com
Mon Nov 18 22:00:41 AEST 2024
Dan Cross <crossd at gmail.com> wrote:
>Programmer ability is certainly an issue, but I would suggest that
>another goes back to what Rob was alluding to: compiler writers have
>taken too much advantage of UB, making it difficult to write
>well-formed programs that last.
Following the letter, rather than the spirit, of the standard?
>The `realloc` function I mentioned earlier is a good case in point;
>the first ANSI C standard says this: "If ptr is a null pointer, the
>realloc function behaves like the malloc function for the specified
>size. ... If size is zero and ptr is not a null pointer, the object it
>points to is freed." While the description of `malloc` doesn't say
>thing about what happens when `size` is 0, perhaps making `realloc(0,
>NULL)` nominally UB (??), the behavior of `realloc(0, ptr)` is clearly
>well defined when `ptr` is not nil, and it's entirely possible that
>programs were written with that well-defined behavior as an
>assumption. (Worth mentioning is that this language was changed in
>C99, and implementations started differing from there.)
>
>But now, C23 has made `realloc(0, ptr)` UB, regardless of the value of
>`ptr`
Something similar happened with so-called strict aliasing, when the
compilers started assuming pointers to incompatible types as always
pointer to different non-overlapping locations:
See, e.g.: <https://www.geeksforgeeks.org/strict-aliasing-rule-in-c-with-examples/>
Linus ranterd about it: <https://lkml.org/lkml/2018/6/5/769>
>My sense is that tossing in bad programmers is just throwing gasoline
>onto a dumpster fire. Particularly when they look to charlatans like
>Robert Martin or Allen Holub as sources of education and inspiration
>instead of seeking out proper sources of education.
I am a bad one as well, to have liked some things in Martin's books
/Clean Code/ and /Clean Architecture/ . True, heis no Wirth, nor
Dijxtra, nor Knuth, but why a charlatan?
More information about the TUHS
mailing list