Surely it always succeeds?
For small programs, and during light testing, it is true that malloc usually succeeds. Unfortunately, there are all sorts of unpredictable reasons why malloc might fail one day; for example: • Someone uses your program for a far larger data set than you anticipated; • Your program is running on a machine with less memory than you expected; • The machine your program is running on is heavily loaded. In this case, malloc will return NULL, and your program will attempt to store data by resolving the null pointer. This might cause your program to exit immediately with a helpful message, but it is more likely to provoke mysterious problems later on. If you want your code to be robust, and to stand the test of time, you must check all error or status codes that may be returned by functions you call, especially those in other libraries, such as the C run-time library.
Related Questions
- Budhists seem to think there is something non-material about the mind. But surely the mind is just the brain, or maybe a program running on the brain?
- Why is it two drops in treatment bottles and in a glass of water -- surely the person taking the glass of water will get more remedy?
- Surely it always succeeds?