Article View: comp.lang.c.moderated
Article #2526Re: Good C Interview questions?
From: Jerry Coffin
Date: Sat, 06 Apr 1996 14:50
Date: Sat, 06 Apr 1996 14:50
27 lines
1567 bytes
1567 bytes
In article <4jv7ri$dam@solutions.solon.com>, mholcomb@BIX.com says...
> Bill Wendling wrote:
> >} Why isn't the size 2*sizeof(int)+2*sizeof(char)?
> >
> >Byte alignment?
> >
> >} How could you decrease the size of the structure without removing
> >} any members?
> >
> >Rearrange the elements.
> >
> Aren't these questions platform dependent?
Yes and no. The standard doesn't assure us of correct answers, but not all
knowledge of C comes from the standard. Given:
typedef struct { long a; char b; } A;
typedef struct { char b; long a; } B;
There's nothing in the standard to require that an A will always be the same
size or smaller than a B. However, it's true with a large enough percentage
of compilers that's I'd consider it basically a fact nonetheless. Most likely
somebody will now feel obliged to hack gcc to align all structure elements to
odd byte boundaries or somesuch to prove that wrong. However, I'm willing to
be that even if they do, they won't use the compiler much this way...
Later,
Jerry.
Technical Details
Message-ID:
<4k60bt$aah@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jmcn5$lq6@solutions.solon.com><4jv7ri$dam@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: jcoffin@rmii.com (Jerry Coffin) Newsgroups: comp.lang.c.moderated Subject: Re: Good C Interview questions? Date: 6 Apr 1996 08:50:37 -0600 Organization: TAEUS Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k60bt$aah@solutions.solon.com> References: <4jmcn5$lq6@solutions.solon.com><4jv7ri$dam@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: MicroPlanet News32 v1.00 Beta Build 302