Mail Archives: djgpp/1997/04/17/23:35:10
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. ;)
--
John M. Aldrich <fighteer AT cs DOT com>
* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
again.
* It doesn't necessarily do it in chronological order, though.
--- Douglas Adams
- Raw text -