Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lakesys!chad From: chad@lakesys.UUCP (Chad Gibbons) Newsgroups: comp.lang.c Subject: malloc() and sizeof Message-ID: <510@lakesys.UUCP> Date: 3 Apr 89 08:08:36 GMT Reply-To: chad@lakesys.UUCP (Chad Gibbons) Distribution: usa Organization: Lake Systems - Milwaukee, Wisconsin Lines: 19 I have seen a somewhat strange style of coding a malloc() call on some systems. Usually, given struct foo, you would execute the call such as this: struct foo tmp = (struct foo *)malloc(sizeof(struct foo)); The style I have seen used recently around here has been this: struct foo tmp = (struct foo *)malloc(sizeof *tmp); 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? I would assume it wouldn't be a good idea to use it, but then again, you never know. -- D. Chadwick Gibbons, chad@lakesys.lakesys.com, ...!uunet!marque!lakesys!chad