Path: utzoo!attcan!uunet!cs.utexas.edu!execu!sequoia!rpp386!jfh From: jfh@rpp386.cactus.org (John F. Haugh II) Newsgroups: comp.std.c Subject: Re: [m]allocation question Message-ID: <18552@rpp386.cactus.org> Date: 29 Sep 90 00:20:44 GMT References: <11666:Sep2603:44:3190@kramden.acf.nyu.edu> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 32 X-Clever-Slogan: Recycle or Die. In article <11666:Sep2603:44:3190@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article ghoti+@andrew.cmu.edu (Adam Stoller) writes: >> t = (struct node *) malloc(sizeof *t); > >The argument of sizeof isn't evaluated. Only its type matters. This is >correct code, and perhaps easier to understand than the other obvious >version. I've been meaning to beg to differ, but looking at the code fragment, the type of "t" is unknown, and thus the size of the allocation. You might argue that "t" is "obviously" (struct node *), but that would be kinda silly - there is no declaration of "t" laying around to stare at, and besides I'm just in the mood to argue. I always try to "say what I mean" when I do mallocs and other naturally obscure stuff (and I'm getting to the point, so bear with me) and would prefer to do t = (struct node *) malloc (sizeof (struct node)); when it is a (struct node) that I want. Otherwise, I would much rather do t = (typeof t) malloc (sizeof *t); but I don't recall "typeof" being part of the standard, so I'll have to hope someone in alt.futures.c screams and dances about this one ;-) -- John F. Haugh II UUCP: ...!cs.utexas.edu!rpp386!jfh Ma Bell: (512) 832-8832 Domain: jfh@rpp386.cactus.org "SCCS, the source motel! Programs check in and never check out!" -- Ken Thompson