🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #914

sizeof on a word-oriented machine

#914
From: Norman Diamond
Date: Thu, 16 Nov 1989 08:14
25 lines
1346 bytes
Consider a machine where each 4-byte word has an address.

  char x[37];
  int  q;
  q = sizeof x / sizeof (char);

What is sizeof x?

If sizeof x is 40 (since 40 bytes are reserved for x) then the example
on page 46 lines 12 to 13 (section 3.3.3.4) is violated.

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.

I think 40 is the most reasonable value for sizeof x.  Is the standard's
example wrong?  May it be ignored?

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".
Technical Details
Message-ID: <11135@riks.csl.sony.co.jp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond
From: diamond@csl.sony.co.jp (Norman Diamond)
Newsgroups: comp.std.c
Subject: sizeof on a word-oriented machine
Message-ID: <11135@riks.csl.sony.co.jp>
Date: 16 Nov 89 08:14:34 GMT
Reply-To: diamond@ws.sony.junet (Norman Diamond)
Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan
Lines: 25