Am 01.09.25 um 17:35 schrieb Maarten Brock:
Philipp Klaus Krause schreef op 2025-09-01 17:19:
C99TC2 (also C99TC3 and C11): "[…] If memory for the new object cannot
be allocated, the old object is not deallocated and its value is
unchanged."
ISO/IEC 9899:TC3:
J.3 Implementation-defined behavior
A conforming implementation is required to document its choice of
behavior in each of
the areas listed in this subclause. The following are implementation-
defined:
[...]
J3.12 Library functions
[...]
— Whether the calloc, malloc, and realloc functions return a null
pointer or a
pointer to an allocated object when the size requested is zero (7.20.3).
To me this says that as long as we document the current implementation
it is all right.
This gives us the right to return null (as we currently do), or an
allocated object (as I want to do in the future).
But IMO this does not give us the right to free the old object if we
return a null pointer. Thus I think our current implementation is
non-compliant.
Philipp
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user