Hi Doug,
> >
malloc(0) isn't undefined behaviour but implementation defined.
>
> In modern C there is no difference between those two concepts.
There certainly is a difference, but in this case the practical
implications are the same: avoid malloc(0).
Many programs wrap malloc() in some way, even if it's just to exit on
failure, so working around malloc(0) is easy enough.
void *saneloc(size_t size) {
void *p = malloc(size);
if (p || size)
return p;
return malloc(1);
}
In the middle is the default signedness of chars,
which generally may
be mitigated by explicit type declarations.
Similarly, the signedness of an ‘int i: 3’ bit-field.
(1) Whether a "plain" int bit-field is treated as a signed int
bit-field or as an unsigned int bit-field (6.7.2, 6.7.2.1).
Is there any other C construct that
implementation-definedness renders
useless?
There's the '-' in "%[3-7]" for fscanf(3).
(35) The interpretation of a − character that is neither the first
nor the last character, nor the second where a ^ character is
the first, in the scanlist for %[ conversion in the fscanf or
fwscanf function (7.23.6.2, 7.31.2.1).
--
Cheers, Ralph.