home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #23 / NN_1992_23.iso / spool / vmsnet / internal / 1435 < prev    next >
Encoding:
Internet Message Format  |  1992-10-10  |  1.6 KB

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!wupost!usc!elroy.jpl.nasa.gov!ames!network.ucsd.edu!mvb.saic.com!macro32
  2. From: Yaacov Fenster @ISO 882-3153  10-Oct-1992 1823
  3. Newsgroups: vmsnet.internals
  4. Subject: RE: malloc() as a user defined function
  5. Message-ID: <9210101619.AA20403@vbormc.vbo.dec.com>
  6. Date: Sat, 10 Oct 92 17:19:17 MET
  7. Organization: Macro32<==>Vmsnet.Internals Gateway
  8. X-Gateway-Source-Info: Mailing List
  9. Lines: 42
  10.  
  11. > From: VBORMC::"MACRO32@WKUVX1.BITNET" "MAIL-11 Daemon"  9-OCT-1992 21:28:56.38
  12. > To:   MACRO32@WKUVX1.BITNET
  13. > CC:
  14. > Subj: malloc() as a user defined function
  15. >
  16. >
  17. > Hi netters:
  18. >
  19. >     In programming on dynamic memory allocation, I prefer doing check on
  20. >     every malloc(). I.e.:
  21. >
  22. >     if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
  23. >         printf("Malloc error.\n");
  24. >         exit(0);
  25. >     }
  26. >
  27. >     It turned out it's a pain to type in the above four lines if I have
  28. >     lots of malloc() invocations in the program, also, the program looks
  29. >     ugly. So I tried to use a function called my_malloc():
  30. >
  31. >     SOME_TYPE *my_malloc()
  32. >     {
  33. >         SOME_TYPE *p;
  34. >
  35. >         if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
  36. >             printf("Malloc error.\n");
  37. >             exit(0);
  38. >         }
  39. >         return(p);
  40. >     }
  41. >
  42. Try my_malloc() returning type of "void *", this will convert into any "type *"
  43. type.
  44.  
  45.         Yaacov
  46.  
  47. -------------------------------------------------
  48. Yaacov Fenster                  +(972)-3-9307239
  49. y.fenster@ieee.org
  50. fenster@taveng.enet.dec.com     DTN 882-3153
  51. All the opinions voiced are mine alone and do not reflect anyone else's
  52. opinion. (Including Dec).
  53.