Empty class passing details

Jim Dehnert dehnert at baalbek.engr.sgi.com
Sat Nov 18 00:26:00 UTC 2000


> Subject: Empty class passing details
> From: Mark Mitchell <mark at codesourcery.com>
> Date: Mon, 13 Nov 2000 11:39:24 -0800
>
> We should also say what to do with return values.  And, I think in the
> spirit of easy reading, we should say:
> 
>   as thought it were a struct containing a single char, i.e., 
>   `struct S { char c; };'

Done.  Take a look.


> Subject: Re: Empty class passing details
> From: Mark Mitchell <mark at codesourcery.com>
> Date: Mon, 13 Nov 2000 12:06:17 -0800
> 
> Will wonders never cease...
> 
> David Gross points out that an empty class can have size greater than
> one.  (Conflicts from base classes that can't go at the same
> address...)
> 
> I bet I have made this assumption in code in a few places, and I bet
> it's implied several places in the draft ABI, too.
> 
> There are two ways to fix this:
> 
>   - Change the definition of empty class to say a class that has 
>     no data members, etc., and has size one.
> 
>   - Make a pass through everything fixing it up.
> 
> This case is sufficiently pathological (empty classes with multiple
> inheritance, eventually from the same base class) that nobody will
> mind a bit if we choose the first option, so that's the one I would
> favor.

I don't know that we've made this assumption anywhere, though there are
places (parameter passing) where it might prove inconvenient IF the
empty class got bigger than a parameter register.  Given that such a
class can't have any virtual bases or functions, I'm frankly not
worried that this will _ever_ happen, let alone infrequently.  So I'm
inclined to ignore it unless someone sees a place where we've got it
wrong.

Now I have a bias (laziness), but I'd rather not risk inserting
inconsistencies if it's not necessary.

Jim

-	    Jim Dehnert		dehnertj at acm.org




More information about the cxx-abi-dev mailing list