Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cica!iuvax!mailrus!sharkey!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: SIMPLE malloc & pointer question Message-ID: Date: 7 Aug 90 15:18:56 GMT References: <7206@helios.TAMU.EDU> Sender: news@adi.COM Organization: Applied Dynamics Int'l. Lines: 42 In-reply-to: jdm5548@diamond.tamu.edu's message of 7 Aug 90 02:08:58 GMT jdm5548@diamond.tamu.edu (James Darrell McCauley) asked about setting a function argument. The answer has been given elsewhere (argument values are local; changes are not passed back to the parent). I just have small style quibbles. main() { ... inita(a,b); ... } inita (a,b) int a[],b[]; { a=(int *)malloc( (unsigned) 4*sizeof(int)); ... } I have style rules to avoid confusion in the reader and to avoid bugs: * I declare before use, even if the compiler seems to let me get away with it. inita was not a problem only because it returns type int. * I don't try to lie to the compiler. If a function doesn't return a value, I define it "void". If a function is taking a pointer as argument, I say so, because you can't pass arrays as arguments in C. Inita falls under both these points. So I would have written void inita (a,b) int *a, *b; { ... } main () { ... } -- "I'm not a nerd -- I'm 'socially challenged'." Tim McDaniel Internet: mcdaniel@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel