[Tfug] Developer question

Bexley Hall bexley401 at yahoo.com
Sat Jul 7 11:23:50 MST 2007


--- Robert Hunter <hunter at tfug.org> wrote:

> On 7/6/07, Bexley Hall <bexley401 at yahoo.com> wrote:
> > > enum color_t {
> > >        /* must begin with 0, so sayeth the
> standard
> >
> > Actualy, that's just the example context... you
> can
> > begin with damn near *anything*!  :>
> 
> Yes, I realized as soon as I sent that email that
> there was a potential
> misunderstanding.  What I *meant* to say is that in
> the absence of an
> explicit specifier, enum begins with zero.
> 
> > Obviously, I don't trust people to dot i's and
> cross t's
> 
> The difficulty, as I see it, is that you are trying
> to prevent an intent
> error using syntactic mechanisms.  Strictly
> speaking, it is impossible to
> do this, although you may be able to make it
> blindingly obvious how your
> code should be handled by other developers.
 
I can't *prevent* people from writing code that
is syntactically correct.  *But*, I can write
*my* parts of the code to ensure that they at
least have to go digging to find *why* my code is
complaining and, presumably, *fix* their problem
to silence my complaints, etc.

E.g.,

ASSERT(sizeof(colornames[])/sizeof(colornames) ==
COLOR_T_NUMBER)

followed by a comment (when they go looking through
the code to *find* the failed assertion) that says:

// There be dragons here!
// Ensure the number of entries in colornames[]
// coincides with the number of colors defined in the
// color_t enumeration.
// Each entry should name the corresponding
enumeration
// constant... blahblahblah


       
____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222




More information about the tfug mailing list