Der Titel sagt fast alles, aber ich werde die Frage wiederholen ...Ist das folgende Programm ein striktes C99-Programm?
Ist das folgende Programm ein "streng konformes Programm" unter dem C99-Standard?
#include <stdlib.h>
/* Removing any pre-existing macro definition, in case one should exist in the implementation.
* Seems to be allowed under 7.1.3 para 3, as malloc does not begin with _X where X is any capital letter.
* And 7.1.4 para 1 explicitly permits #undef of such macros.
*/
#ifdef malloc
#undef malloc
#endif
/* Macro substitution has no impact on the external name malloc
* which remains accessible, e.g., via "(malloc)(s)". Such use of
* macro substitution seems enabled by 7.1.4 para 1, but not specifically
* mentioned otherwise.
*/
void * journalling_malloc(size_t size);
#define malloc(s) ((journalling_malloc)(s))
int main(void)
{
return malloc(10) == NULL ? 1 : 0;
/* Just for the sake of expanding the
* macro one time, return as exit code
* whether the allocation was performed.
*/
}
BTW, ich bin mir bewusst, dass man auch frei(), realloc(), strdup(), calloc() und who-knows-what-sonst "wrap" möchte. Das ist nicht die Frage. Nebenbei bemerkt: Wer weiß was noch? Das sind all die malloc() API, die ich aus meinem Kopf zaubern kann. –
Ich möchte nur erwähnen, dass diese Methode wird nicht mit Malloc Verwendung in externen Bibliotheken helfen. Einige Leute bieten alternative malloc-Implementierungen an, die zur Linkzeit hinzugefügt werden können, zum Beispiel google http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools – gnud