null args to macros in ANSI C

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Oct 7 12:12:03 AEST 1989


In article <1989Oct9.195333.2544 at comp.vuw.ac.nz> mark at comp.vuw.ac.nz (Mark Davies) writes:
>Is objecting to the following bit of code an ANSI'ism?
>#define mem_alloc(s) malloc(s)
>extern char *mem_alloc();

No, it's simply incorrect use of C, and pre-ANSI implementations should
also complain about it.

Note also that malloc() should NOT be declared by the application under
a standard-conforming implementation; instead #include <stdlib.h>.  The
function returns void* in conforming implementations.

I don't know why you want to rename malloc, but
	#define mem_alloc malloc
will do it correctly.

>Why doesn't ANSI C allow the arguments of macros to be null strings?

There are numerous reasons.  Making this work in full generality involves
some tricky engineering, and not enough of the committee were convinced
that it was worth the effort.



More information about the Comp.lang.c mailing list