gwyn@smoke.BRL.MIL (Doug Gwyn) (10/07/89)
In article <1989Oct9.195333.2544@comp.vuw.ac.nz> mark@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.
mark@comp.vuw.ac.nz (Mark Davies) (10/10/89)
Is objecting to the following bit of code an ANSI'ism? #define mem_alloc(s) malloc(s) extern char *mem_alloc(); gcc 1.36 complains (well actually its preprocessor does) about no args to macro `mem_alloc' and code seems to have been added to explicitly catch this case (when not invoked with -traditional). Why doesn't ANSI C allow the arguments of macros to be null strings? Admittedly if the above was "real" ANSI code it would be prototyped and so would work. mark -- mark@comp.vuw.ac.nz | ...!uunet!vuwcomp!mark | DEV_BSIZE forever!
mark@comp.vuw.ac.nz (Mark Davies) (10/13/89)
In article <11247@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <1989Oct9.195333.2544@comp.vuw.ac.nz> I wrote: >>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. I don't normally. Sun did. The actual bit of code this occured in was part of sunrpc. rpctypes.h includes the following bit of code : #ifndef KERNEL extern char *malloc(); #define mem_alloc(bsize) malloc(bsize) #define mem_free(ptr, bsize) free(ptr) : then xdr_reference.c does the following : #include "rpctypes.h" /* <> */ : : char *mem_alloc(); : Just another example of Sun writing bogus code it seems. mark -- mark@comp.vuw.ac.nz | ...!uunet!vuwcomp!mark | DEV_BSIZE forever!