Path: utzoo!utgpu!watmath!clyde!att!rutgers!mailrus!ames!oliveb!felix!arcturus!evil From: evil@arcturus.UUCP (Wade Guthrie) Newsgroups: comp.lang.c Subject: Re: What should "sizeof (expression)" return? Why "8" ?? Summary: a novice trys to answer Keywords: sizeof expression Message-ID: <2976@arcturus> Date: 8 Dec 88 17:02:07 GMT References: <654@sbsvax.UUCP> Organization: Rockwell International, Anaheim, CA Lines: 56 Well, I am a relative novice, but how do we learn without trying and experiencing the flame of disappointment :-) In article <654@sbsvax.UUCP>, greim@sbsvax.UUCP (Michael Greim) asks about the output of the sizeof operator in regards to the following program: [abridged for the line counter] > struct misty {unsigned int a1:1; unsigned int a2:15;}mist; > int i; > float r; > char s [20]; > > main () > { > printf ("sizeof(mist.a1) [1 bit] = %d\n", sizeof(mist.a1)); > printf ("sizeof(c1printf ("sizeof(i+r) = %d\n", sizeof (i+r)); > printf ("sizeof(i+s) = %d\n", sizeof (i+s)); > } well, each of the sizeofs are in the form of sizeof expression, so let's dicect each expression to figure out what it should print. First, sizeof(mist.a1) -- well, my guess (and this is pretty shakey) is that mist.a1 is really just a single bit of an unsigned int and not an entity of itself, so its size is that of an unsigned int, which, on the VAX, is 4 bytes. sizeof(c1