This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Compiling GCC with g++: a report


Zack Weinberg <zack@codesourcery.com> writes:

| On Tue, 2005-05-24 at 20:27 -0400, DJ Delorie wrote:
| > > This is still not an answer to the question I originally asked - do you
| > > see any way IN C to write code which has the relevant property of the
| > > class above (that is, that the FOOmode constants are not accessible
| > > except to authorized code) and which does not rely on free conversion
| > > between enumeration constants and integral types?
| > 
| > enum {
| >   TVQ_BAR_GRILL = (DATESTAMP % 10),
| >   TVQ_NEXT2,
| >   TVQ_NEXT3,
| >   TVQ_NEXT4
| > } TheValQuux;
| > 
| > It's evil, but it will keep programmers from hard-coding integer
| > constants anywhere.  The "constants" will need to be different every
| > day.
| 
| This doesn't do what I want at all.  The goal is to make the *symbolic
| enumeration constants* inaccessible to most code.

But, you wrong in that goal.  The goal should not be to prevent access
to the names, but to prevent access to the values behind the names.  
You are looking at the wrong thing.

| Think about how machine_mode values are used.
                               ^^^^^^

That is the key.  *Values*.  You want to make sure the invariants for
the values are kept consistent.  Not, that the names that designate
the values are inaccessible.

| Almost the entire
| compiler is supposed to treat them as opaque things.

Yes, and the names do provide that abstraction layer.  Furthermore, if
you remove the current type mocking unsigned int <-> int <-> enums,
you do make a step further toward making sure that people treats the
machine_mode values as opaque.

|  You get them from
| e.g. int_mode_for_size; you may iterate over a class with
| GET_MODE_WIDER_MODE; you stash them in RTL and you pass them to
| predicates.  Appearances of "SImode" in the machine-independent compiler
| are usually bugs.

That is wrong.  If you remove the names and provide interface where
people use integers and type casts, you promote more opportunities for
bugs.  That is not what you want.  You want something different.  You
want better control.  The need for iterating over the modes is real.
So what you do is provide an interface for that.  In the earlier
message, I even said I used macros NEXT(), PREV().

|  This is a major contributing factor to the brokenness
| of ports that don't set BITS_PER_UNIT==8.
| 
| The goal is to make "SImode" and its friends inaccessible in the

No, the goal is to make the *values* inaccessible, not the names.

| machine-independent compiler, so that that category of bugs cannot
| arise.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]