malloc doc omits errno

The IEEE spec declares that malloc() sets errno on error, but this website has no mention of errno for the malloc page.

http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html

http://www.cplusplus.com/reference/cstdlib/malloc/
I believe the IEEE spec is describing the behavior of a POSIX system. The only references to errno I can find in conjunction with malloc() talk about POSIX. Neither the C89 nor C99 standards make any mention of errno in their descriptions of malloc().

http://port70.net/~nsz/c/c89/c89-draft.html#4.10.3.3
http://port70.net/~nsz/c/c99/n1256.html#7.20.3.3
If the function returns a clear error value (NULL) and there is only one possible error code, then the error code adds nothing. Note that the error code you are referring to is marked CX, meaning it is an extension.
Last edited on
there is only one possible error code
What makes you think there is only one reason why malloc() can fail? It might be:
- the system is out of memory. In that case, retrying might succeed because some other program might free up memory.
- The program has exceeded the possible address space. Not much you can do.
- The program has exceeded a configurable maximum size.
etc.
I didn't say "there is only one reason". I said "there is only one possible error code". I certainly didn't mean to suggest that more error codes weren't possible (as it may have sounded), just that there is only one error code specified in the linked documentation, so if malloc fails, that must be the error code that was set. Therefore there's not much point testing for it. The error description, "Insufficient storage space is available", is generic enough to fit all of your examples. Obviously a particular implementation can specify extra codes if it wants to give more detailed information. However, neither linux nor MS seem to specify any additional codes.
Topic archived. No new replies allowed.