From: md2828 AT mclink DOT it (Marco Salvalaggio) To: "John M. Aldrich" Cc: djgpp AT delorie DOT com Subject: Re: Try this one on for size Date: Fri, 18 Apr 1997 22:09:43 GMT Message-ID: <3359f11f.3787725@newmail.mclink.it> References: <199704162029 DOT QAA02720 AT hcst DOT net> <33546C31 DOT 6872 AT NO DOT SPAM DOT cs DOT com> <335631CF DOT 1F90 AT cornell DOT edu> <3355D38F DOT ED2 AT NO DOT SPAM DOT cs DOT com> In-Reply-To: <3355D38F.ED2@NO.SPAM.cs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk On Thu, 17 Apr 1997 07:38:55 +0000, you wrote: >A. Sinan Unur wrote: >> >> > struct big_bad_struct *x; >> > x = malloc( sizeof(x) ); >> > >> > I leave it up to you to determine why this is wrong. ;) >> >> x = (struct big_bad_struct *) malloc (sizeof(big_bad_struct)); >> >> sorry, couldn't resist the temptation. > >While you're right in principle, one of the tenets of abstract design is >that you should have as little contact with the internals of a data >structure as possible. Using the variable name itself makes for much >more understandable code, IMHO. Then again, maybe not. I'm not going >to get into an argument about it. ;) > I agree with your opinion, but in this case the variable's name was *x so the correct operation would be: x = malloc( sizeof(*x) );