POV-Ray : Newsgroups : povray.off-topic : This is the sort of brokenness... : Re: This is the sort of brokenness... Server Time
7 Sep 2024 03:20:05 EDT (-0400)
  Re: This is the sort of brokenness...  
From: Warp
Date: 20 Mar 2009 02:41:28
Message: <49c33a98@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Consider the case of "class alpha 
> {int abc;}" for a counter-example - I know exactly how that's laid out due 
> to the standard.

  I don't think the standard specifies what kind of padding the compiler
will use between member elements.

  For example, if you have a "struct { char c; int i; };", how many bytes,
if at all, are there between 'c' and 'i'?
  Suppose you have "struct { int i; long l; };" in a 64-bit system. Will
the compiler put padding bytes between 'i' and 'l' or not?

  Suppose you have:

class A {};
class B: public A { int i; };

  sizeof(A) will be, per the C++ standard, at least 1. But what will be
sizeof(B), and consequently the offset of 'i' inside it? The standard
doesn't specify, and the compiler is free to optimize the empty base
class away or not, as it sees fit.

  Oh, and it becomes even more complicated:

class A { int i1; public: virtual ~A(); };
class B1: virtual public A { int i2; };
class B2: virtual public A { int i3; };
class C: public B1, public B2 { int i4; };

  Want to start guessing the offsets of the ints inside C? Good luck.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.