Path: utzoo!attcan!uunet!samsung!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: sizeof on a word-oriented machine Message-ID: <11626@smoke.BRL.MIL> Date: 17 Nov 89 15:59:12 GMT References: <11135@riks.csl.sony.co.jp> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <11135@riks.csl.sony.co.jp> diamond@ws.sony.junet (Norman Diamond) writes: -Consider a machine where each 4-byte word has an address. - char x[37]; -What is sizeof x? 37. -If sizeof x is 37 then a user might do: - char *two_xs; - two_xs = malloc (2 * sizeof x); -and get screwed because only 76 bytes will be allocated (2 * 37 rounded -up to a multiple of 4) when 80 are really needed. No, only 2*37 bytes are needed. Arrays are not padded. -I think 40 is the most reasonable value for sizeof x. Is the standard's -example wrong? May it be ignored? The example is right. Feel free to ignore it.