Mail Archives: djgpp/1997/04/18/18:26:46
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 -