This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [ob] Remove initializations of memset'd structure
Daniel Jacobowitz writes:
> On Tue, Feb 17, 2004 at 02:33:27PM -0500, Elena Zannoni wrote:
> > Eli Zaretskii writes:
> > > > From: Elena Zannoni <ezannoni@redhat.com>
> > > > Date: Tue, 17 Feb 2004 09:30:06 -0500
> > > > > >
> > > > > > - MSYMBOL_TYPE (m) = mst_unknown;
> > > > >
> > > > > This part of the patch seems to assume that mst_unknown has the value
> > > > > zero. Should we have such assumptions in the code?
> > > >
> > > > Yes, in symtab.h mst_unknown is 0.
> > >
> > > I know that, I looked it up in symtab.h. The question is, should the
> > > code rely on the fact that zeroing out the struct causes the
> > > MSYMBOL_TYPE member to become mst_unknown. Suppose we change the
> > > enumeration some day, that would break the code.
> > >
> >
> > Oh, I see. I misunderstood you.
> >
> > > So I think a comment is not enough, we should leave that line alone.
> > > In general, it is my opinion that code should not assume anything
> > > about the numerical values of enumerated types.
> >
> > That's true. It would be safer to leave the line alone. I'll change
> > it back. Also language_unknown is used similarly.
> >
> > I've committed this.
>
> Thanks. The only downside is that this suggests the type of the
> terminating symbol can ever be read without being in error, which is
> incorrect; the minimal symbol table's end appears to be marked by
> otherwise by SYMBOL_LINKAGE_NAME (msym) == NULL. Other minimal symbols
> may have type mst_unknown.
>
I am not sure I follow your sentence. If you are worried that the
value 0 can indicate a perfectly legal msymbol, this is no different
from the situation we end up with when just using the memset. You can
always add a new enum value of mst_bogus (pick your name) and use that
in the terminating msym. BTW, there is almost identical code in
minsyms.c:install_minimal_symbols.