Naming

Michael Friedman mfriedma at oracle.com
Thu Mar 1 07:56:01 AEST 1990


In article <MCDANIEL.90Feb28121657 at amara.amara.uucp} mcdaniel at amara.uucp (Tim McDaniel) writes:
}gwyn at smoke.BRL.MIL (Doug Gwyn) writes:

}   You may #define your own malloc macro only if you don't #include <stdlib.h}.
}   ...
}   It would be better to use some name other than malloc for this macro.

}Let me be more clear about an intended application.  We'd like to have
}ANSI C library semantics available on all our development platforms.

You seem to be unnecessarily looking for trouble.

Why does your memory allocation routine have to be given the same name
as the ANSI C routine?

Why not use ANSImalloc in all of your code and just #define it to
malloc whenever you can?

}For instance, free given a NULL argument could just do nothing (if the
}platform's supplied free would abort in such a circumstance).  We also
}might like to have some sort of exception handling facility, or
}manually record a stack trace.
}
}In such a case, we'd just like to have a wrapper around the "real"
}function:
}    extern void * our_malloc(size_t);
}    #undef malloc
}    #define malloc(x) our_malloc(x)
}where our_malloc does wrapperish stuff and then calls the real malloc
}to do the real work.  We'd set up "our_stdlib.h" with such
}declarations.
}
}So, if we ever #include <stdlib.h}, even if I #undef malloc as a
}precaution, I can't #define a new malloc?  That's a bummer.  (Since
}we'll have an own_stdlib.h, there's a workaround, but it's still an
}annoyance.)
}
}I assume the reasoning is that the compiler might have, say, malloc()
}as a builtin, enabled upon seeing
}    #include <stdlib.h}
}However, it would have been easy to mandate that there be a way to
}turn it off, say via
}    #undef malloc
}after the #include.  Oh well, too late now.
}--
}Tim McDaniel
}Applied Dynamics International, Ann Arbor, MI
}Internet: mcdaniel%amara.uucp at mailgw.cc.umich.edu
}UUCP: {uunet,sharkey}!amara!mcdaniel


--
The passing of Marxism-Leninism first from China and then from the
Soviet Union will mean is death as a living ideology ... .  For while
there may be some isolated true believers left in places like Managua,
Pyongyang, or Cambridge, MA ...   - Francis Fukuyama



More information about the Comp.std.c mailing list