www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/11/06/08:33:54

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,comp.os.msdos.djgpp
Subject: Re: Holes in structure
Followup-To: alt.comp.lang.learn.c-c++
Date: 6 Nov 2001 13:20:13 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 43
Message-ID: <9s8o2d$nl6$1@nets3.rz.RWTH-Aachen.DE>
References: <3BE7D280 DOT C1732E58 AT bigfoot DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 1005052813 24230 137.226.32.75 (6 Nov 2001 13:20:13 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 6 Nov 2001 13:20:13 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

[Crossposted without a proper F'up2 --- I restricted it to one group
as it should be]

In comp.os.msdos.djgpp Alex Vinokur <alexvn AT bigfoot DOT com> wrote:

> Here is some program that detects holes in structure.

A rather useless exercise, that is.  You don't need to know or detect
this kind of information.  If you think you have to, you should
re-think the arguments that brought you to this conlusion.  At least
one of them is flawed.

> Its output is not perfectly clear to me.

[...]
> Questions.
>  1. struct type0 (empty) :
>            Why is 'sizeof' = 1?

Why not?  An empty struct is a completely useless thing --- what on
earth would you care about its size for?

>  2. struct type1 :
>            Why is not 'Diff' (between 'sizeof' and 'All items sum')
>   equal 'All holes sum' ?

The thing you're investigating here is not called "hole"s, that's why.
It's called "padding", and that included possible padding at the *end*
of a structure, after the last element. That's exactcly where the
remaining three bytes of "holes" are, in this particular case.

>  3. struct type0 and type1 :
>            Why is not ('Diff' - 'All holes sum') the same value for
> type0 and type1.
>            Note. type0  : 'Diff' - 'All holes sum' = 1 - 0 = 1
>                  type1  : 'Diff' - 'All holes sum' = 9 - 6 = 3

Why should they be the same?


-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019