Il titolo quasi dice tutto, ma io vi riformulare la domanda ...Il seguente programma è un programma C99 rigorosamente conforme?
è il seguente programma un "programma strettamente conforme" sotto lo standard C99?
#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, sono consapevole che uno vorrebbe anche "wrap" free(), realloc(), strdup(), calloc() e who-knows-what-else. Questa non è la domanda. Una nota a margine: chissà cos'altro? Queste sono tutte le API malloc() che posso evocare dalla mia testa. –
Voglio solo ricordare che questo metodo non aiuta l'uso di malloc in nessuna libreria esterna. Diverse persone forniscono implementazioni malloc alternative che possono essere aggiunte al momento del collegamento, ad esempio google all'indirizzo http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools – gnud