Compiling GCC with g++: a report

Mark Mitchell mark@codesourcery.com
Tue May 24 07:04:00 GMT 2005


Zack Weinberg wrote:
> Mark Mitchell <mark@codesourcery.com> writes:
> 
> [snip stuff addressed elsewhere]
> 
>>I agree with the goal of more hiding.
>>
>>You can do this in C by using an incomplete structure type in most
>>places, and then, in the files where you want the definition visible,
>>defining the structure to have a single field of the enumerated
>>type. That is a little messy, but it is C++-compatible.  (In fact, in
>>ISO C++, without the additions presently in the WP, you can't do
>>better; forward declarations of enums are still not allowed.)
> 
> 
> Doesn't work, at least not as a drop-in replacement; you can't pass an
> incomplete structure by value.  We do do this in places where there's
> a real structure that can be passed around by pointer...

Good point; yes, you would have to pass a pointer.  I guess you could 
create a singleton representative of each value in the enum, and pass 
them around, but I agree that's getting pretty ugly.  Of course, the 
problem with "unsigned int" is that it is a complete type, and people 
can accidentally pass in "7", even if there's no such enumeral.  You 
really want forward-declared enums, but you haven't got them; it may be 
you just lose. :-(

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304



More information about the Gcc mailing list