Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!lll-winken!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.lang.c Subject: Re: malloc() and sizeof Message-ID: <1378@auspex.auspex.com> Date: 4 Apr 89 05:07:49 GMT References: <510@lakesys.UUCP> Reply-To: guy@auspex.auspex.com (Guy Harris) Distribution: usa Organization: Auspex Systems, Santa Clara Lines: 22 > I ran tests of this on several different systems, and they all >compiled and worked fine...however, this seems to be a poor programming >practice at best, and a shoestring at worse. Anyone have any comments >about this? Well, in the December 7, 1988 dpANS, kt gives as an example of "sizeof", on page 46: double *dp = alloc(sizeof *dp); so I presume they intend it to be usable, and even that they don't think it's too weird. As for more formal guarantees, we have on page 45: 3.3.3.4 The "sizeof" operator ... ...The size is determined from the type of the operand, which is not itself evaluated. so I'd say that "dp" doesn't have to point to anything reasonable for "sizeof *dp" to be valid.