Xref: utzoo comp.sys.ibm.pc:45263 comp.lang.c:26346 Path: utzoo!utgpu!jarvis.csri.toronto.edu!helios.physics.utoronto.ca!ists!yunexus!geac!maccs!cs4g6ag From: cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: TC bug in sizeof()? Message-ID: <25E9856C.8135@maccs.dcss.mcmaster.ca> Date: 26 Feb 90 19:37:16 GMT References: <1519@maytag.waterloo.edu> Reply-To: cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) Organization: McMaster University, Hamilton, Ontario Lines: 20 In article <1519@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes: $A friend of mine has found something surprising in TC. Neither of us knows $C well enough to know for sure that this is a bug, but it looks like one. $As illustrated in the program below, if a structure is an odd size, and $is compiled with Word alignment, the sizeof function rounds the size up $one byte. $Is this a bug? Well, it depends on how you define "bug" ... I don't have a copy of K&R to check exactly what they say about it, but according to their definition it may be. However, it does make sense, since when compiled with word alignment that extra byte is not available for anything else and is allocated along with the structure. Since it's reflecting the way things really work, you could say it's the most accurate way of doing it. -- Stephen M. Dunn cs4g6ag@maccs.dcss.mcmaster.ca = "\nI'm only an undergraduate!!!\n"; **************************************************************************** I Think I'm Going Bald - Caress of Steel, Rush