Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

malloc free sizeof

Name: Anonymous 2012-01-13 9:51

How do I implement a simple mallow, free, and widely in ask x86?
How does free know how much to actually free?

Name: Anonymous 2012-01-13 15:09

>>25
You can't be sure. But the #ifndef means that on a conforming implementation, the #define has no effect. It merely checks for the existence of the identifier. On a non-conforming implementation, however, #include itself could do anything, or the preprocessor may not even exist. And yes, if a string.h doesn't have NULL, it may not have size_t either, and the functions it does have could be missing, broken or defined to remove() every file on the system. Either way, that doesn't make that code non-conforming, it just makes it superfluous.
#ifdef THIS_IS_A_UNIX_SYSTEM
#include <unistd.h>
#endif
#ifdef THIS_IS_A_WINDOWS_SYSTEM
#include <windows.h>
#endif
#ifdef __STDC_HOSTED__
#include <stdio.h>
#endif
#ifndef NULL
/* if NULL was previously defined, this will do nothing */
#define NULL ((void *)0)
#endif

This is also conforming C89/C99/C11 code. That's how conditional compilation works.

Newer Posts