delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/18/18:26:46

From: md2828 AT mclink DOT it (Marco Salvalaggio)
To: "John M. Aldrich" <fighteer AT NO DOT SPAM DOT cs DOT com>
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

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) );

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019