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

  1. Path: sparky!uunet!stanford.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!news.service.uci.edu!unogate!mvb.saic.com!macro32
  2. From: REGI's <NUNEZ@esevvx.cica.es>
  3. Newsgroups: vmsnet.internals
  4. Subject: (None)
  5. Message-ID: <01GPZGKY0HOG0001ZZ@esevvx.cica.es>
  6. Date: Thu, 15 Oct 1992 16:50:00 UTC+0100
  7. Organization: Macro32<==>Vmsnet.Internals Gateway
  8. X-Gateway-Source-Info: Mailing List
  9. Lines: 71
  10.  
  11. >X-Envelope-to: MACRO32@WKUVX1.bitnet
  12. >X-VMS-To: IN::"MACRO32@WKUVX1.BITNET"
  13.  
  14. 1
  15. 12-OCT-1992 20:01:57.47
  16.    1 00:00:00.00
  17. 13-OCT-1992 20:01:57.47
  18. @UKCC.uky.edu:MacroMan@WKUVX1.BITNET
  19. gutier@SEVAXU.CICA.ES
  20.  
  21. Received: from UKCC.uky.edu by ESEVVX.CICA.ES ;  9-OCT-1992 20:01:54.99
  22. Received: from ukcc.uky.edu by UKCC.uky.edu (IBM VM SMTP V2R2)
  23.    with BSMTP id 5398; Fri, 09 Oct 92 14:59:39 EDT
  24. Received: from WKUVX1.BITNET by ukcc.uky.edu (Mailer R2.08) with BSMTP id 2280;
  25.  Fri, 09 Oct 92 14:59:38 EDT
  26. Errors-To: MacroMan@WKUVX1.BITNET
  27. X-ListName: "VMS Internals, MACRO, and BLISS Discussions"
  28.     <MACRO32@WKUVX1.BITNET>
  29. Received: from CUNYVM.BITNET (MAILER) by WKUVX1 (MX V3.1C) with BSMTP; Fri, 09
  30.           Oct 1992 13:45:16 CDT
  31. Received: from CUNYVM by CUNYVM.BITNET (Mailer R2.08) with BSMTP id 9601; Fri,
  32.           09 Oct 92 13:47:31 EDT
  33. Received: from MVB.SAIC.COM by CUNYVM.CUNY.EDU (IBM VM SMTP V2R2) with TCP;
  34.           Fri, 09 Oct 92 13:47:29 EDT
  35. Xref: unogate vmsnet.internals:1420 vmsnet.misc:1014 comp.lang.c:21901
  36. X-Newsgroups: vmsnet.internals,vmsnet.misc,comp.lang.c
  37. From: <ytang@red.crayola.cs.psu.edu>
  38. Reply-To: MACRO32@WKUVX1.BITNET
  39. Subject: malloc() as a user defined function
  40. Message-ID: <Bvv6pH.Gzy@cs.psu.edu>
  41. Sender: <news@cs.psu.edu>
  42. Nntp-Posting-Host: red.crayola.cs.psu.edu
  43. Organization: Penn State Computer Science
  44. Date: Fri, 9 Oct 1992 17:17:40 GMT
  45. Lines: 33
  46. To: MACRO32@WKUVX1.BITNET
  47. X-Gateway-Source-Info: USENET
  48.  
  49.  
  50. Hi netters:
  51.  
  52.     In programming on dynamic memory allocation, I prefer doing check on
  53.     every malloc(). I.e.:
  54.  
  55.     if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
  56.         printf("Malloc error.\n");
  57.         exit(0);
  58.     }
  59.  
  60.     It turned out it's a pain to type in the above four lines if I have
  61.     lots of malloc() invocations in the program, also, the program looks
  62.     ugly. So I tried to use a function called my_malloc():
  63.  
  64.     SOME_TYPE *my_malloc()
  65.     {
  66.         SOME_TYPE *p;
  67.  
  68.         if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
  69.             printf("Malloc error.\n");
  70.             exit(0);
  71.         }
  72.         return(p);
  73.     }
  74.  
  75.     However another problem arises, what if I have many distinct types
  76.     of memory space to allocate? That is, I can't use the same type in
  77.     calling my_malloc(). So how can I pass a type to a function?
  78.  
  79.     Thanks for your reponse.
  80.  
  81. - Tang
  82.