home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!wupost!usc!elroy.jpl.nasa.gov!ames!network.ucsd.edu!mvb.saic.com!macro32
- From: Yaacov Fenster @ISO 882-3153 10-Oct-1992 1823
- Newsgroups: vmsnet.internals
- Subject: RE: malloc() as a user defined function
- Message-ID: <9210101619.AA20403@vbormc.vbo.dec.com>
- Date: Sat, 10 Oct 92 17:19:17 MET
- Organization: Macro32<==>Vmsnet.Internals Gateway
- X-Gateway-Source-Info: Mailing List
- Lines: 42
-
- > From: VBORMC::"MACRO32@WKUVX1.BITNET" "MAIL-11 Daemon" 9-OCT-1992 21:28:56.38
- > To: MACRO32@WKUVX1.BITNET
- > CC:
- > Subj: malloc() as a user defined function
- >
- >
- > Hi netters:
- >
- > In programming on dynamic memory allocation, I prefer doing check on
- > every malloc(). I.e.:
- >
- > if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
- > printf("Malloc error.\n");
- > exit(0);
- > }
- >
- > It turned out it's a pain to type in the above four lines if I have
- > lots of malloc() invocations in the program, also, the program looks
- > ugly. So I tried to use a function called my_malloc():
- >
- > SOME_TYPE *my_malloc()
- > {
- > SOME_TYPE *p;
- >
- > if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
- > printf("Malloc error.\n");
- > exit(0);
- > }
- > return(p);
- > }
- >
- Try my_malloc() returning type of "void *", this will convert into any "type *"
- type.
-
- Yaacov
-
- -------------------------------------------------
- Yaacov Fenster +(972)-3-9307239
- y.fenster@ieee.org
- fenster@taveng.enet.dec.com DTN 882-3153
- All the opinions voiced are mine alone and do not reflect anyone else's
- opinion. (Including Dec).
-