Article View: vmsnet.internals
Article #384(None)
From: REGI's
Date: Thu, 15 Oct 1992 15:50
Date: Thu, 15 Oct 1992 15:50
71 lines
2860 bytes
2860 bytes
>X-Envelope-to: MACRO32@WKUVX1.bitnet
>X-VMS-To: IN::"MACRO32@WKUVX1.BITNET"
1
12-OCT-1992 20:01:57.47
1 00:00:00.00
13-OCT-1992 20:01:57.47
@UKCC.uky.edu:MacroMan@WKUVX1.BITNET
gutier@SEVAXU.CICA.ES
Received: from UKCC.uky.edu by ESEVVX.CICA.ES ; 9-OCT-1992 20:01:54.99
Received: from ukcc.uky.edu by UKCC.uky.edu (IBM VM SMTP V2R2)
with BSMTP id 5398; Fri, 09 Oct 92 14:59:39 EDT
Received: from WKUVX1.BITNET by ukcc.uky.edu (Mailer R2.08) with BSMTP id 2280;
Fri, 09 Oct 92 14:59:38 EDT
Errors-To: MacroMan@WKUVX1.BITNET
X-ListName: "VMS Internals, MACRO, and BLISS Discussions"
<MACRO32@WKUVX1.BITNET>
Received: from CUNYVM.BITNET (MAILER) by WKUVX1 (MX V3.1C) with BSMTP; Fri, 09
Oct 1992 13:45:16 CDT
Received: from CUNYVM by CUNYVM.BITNET (Mailer R2.08) with BSMTP id 9601; Fri,
09 Oct 92 13:47:31 EDT
Received: from MVB.SAIC.COM by CUNYVM.CUNY.EDU (IBM VM SMTP V2R2) with TCP;
Fri, 09 Oct 92 13:47:29 EDT
Xref: unogate vmsnet.internals:1420 vmsnet.misc:1014 comp.lang.c:21901
X-Newsgroups: vmsnet.internals,vmsnet.misc,comp.lang.c
From: <ytang@red.crayola.cs.psu.edu>
Reply-To: MACRO32@WKUVX1.BITNET
Subject: malloc() as a user defined function
Message-ID: <Bvv6pH.Gzy@cs.psu.edu>
Sender: <news@cs.psu.edu>
Nntp-Posting-Host: red.crayola.cs.psu.edu
Organization: Penn State Computer Science
Date: Fri, 9 Oct 1992 17:17:40 GMT
Lines: 33
To: MACRO32@WKUVX1.BITNET
X-Gateway-Source-Info: USENET
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);
}
However another problem arises, what if I have many distinct types
of memory space to allocate? That is, I can't use the same type in
calling my_malloc(). So how can I pass a type to a function?
Thanks for your reponse.
- Tang
Technical Details
Message-ID:
<01GPZGKY0HOG0001ZZ@esevvx.cica.es>Path:
arc1-ca.pugleaf.net!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!macro32Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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 From: REGI's <NUNEZ@esevvx.cica.es> Newsgroups: vmsnet.internals Subject: (None) Message-ID: <01GPZGKY0HOG0001ZZ@esevvx.cica.es> Date: Thu, 15 Oct 1992 16:50:00 UTC+0100 Organization: Macro32<==>Vmsnet.Internals Gateway X-Gateway-Source-Info: Mailing List Lines: 71