I have a function that I would like to be able to return special values for failure and uninitialized (it returns a pointer on success).
Currently i
Do not use malloc
for this purpose. It might keep unnecessary memory tied up (if a lot of memory is already in use when malloc
gets called and the sentinel gets allocated at a high address, for example) and it confuses memory debuggers/leak detectors. Instead simply return a pointer to a local static const char
object. This pointer will never compare equal to any pointer the program could obtain in any other way, and it only wastes one byte of bss.