Discussion:
MEM_CHECK(x)
(too old to reply)
Konwen Kuan
2004-02-06 02:16:20 UTC
Permalink
Are we allowed to use this from the header file?
Alexander Smith
2004-02-06 02:48:01 UTC
Permalink
Hi,

Yes, you are allowed to use this - that's why we put it there. This macro,
or one like it, is commonly used by C programmers to make it easy to check
for memory allocation problems. The program you're writing for lab 2
should be small enough that you don't run out of memory. But
theoretically, if you did run out of memory, malloc() would indicate this
by returning NULL. I use a similar macro in my own code to check every
call to malloc, like this:

some_pointer = malloc(sizeof(something));
MEM_CHECK(some_pointer);

This way, if memory allocation fails, your program will exit with an error
message telling you exactly where it happened, which can be really useful
when you're debugging your code.

Alexander
Post by Konwen Kuan
Are we allowed to use this from the header file?
Loading...