Re: ANSI requirement

[email protected] (Nicholas Clark)
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Fri, Jun 11, 2010 at 10:16:05AM -0700, Jan Dubois wrote:
> On Fri, 11 Jun 2010, Ævar Arnfjörð Bjarmason wrote:
> > I vaguely recall someone mentioning that we rely on some features of C
> > that aren't strictly guaranteed by ANSI C, such as the the offset into
> > a struct being the sum of the sizeof() of the struct members that came
> > before in the struct.
> 
> I seriously doubt that we rely on it because it would not work unless
> there is *no* structure padding at all.  Nicholas has been working hard
> to remove most unused padding, but I don't believe there is any code in
> Perl that is adding up sizes of individual struct members.

Yes, that's what I thought too :-)

> And anyways, ANSI C has the offsetof() macro if you ever really need to
> know an explicit offset.

Although I did get tripped up by aggressive but legal Sparc64 compilers -
they're allowed to take advantage of the alignment constraints of a struct
when accessing its members. The case in question was loading two adjacent
32 bit values from an 8-byte aligned structure.

We don't make that mistake now.

Nicholas Clark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.