Re: PATCH: Problem union comparision in TUI

Eli Zaretskii
2005-10-20T08:43:09Z

> Date: Wed, 19 Oct 2005 16:07:51 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: Andrew STUBBS <andrew.stubbs@st.com>, gdb-patches@sources.redhat.com
>
> > The reason is that the code should be clean and self-explanatory.
> > Using the same variable for storing two utterly different objects is
> > IMHO The Mother Of Unclean Code.
>
> Is an untagged union any clearer?

No, it isn't. I suggested to modify the data structure so that the
union is tagged. Did you see that message?

> We've already established (via the bug report) that some of the time,
> the code has no idea which one is in use when comparing them. They're
> used for relative line ordering within a particular window; if it's a
> source window, the lines are sorted by line number, and if it's a
> disassembly window, they're sorted by code address. So in both cases
> it's a "line number"; that's why I favor using a single variable for
> them, although I'm open to alternative suggestions.

Yes, I've read the code before I replied, so I know all that already.
Having read the code, I'm not sure that addresses are used only for
disassembly windows and line numbers only for source windows. We
could have more bugs; that's why I think cleaning the code is
important.

I think it shouldn't be too hard to make the change I suggested, since
most of it boils down to mechanically adding either the line or
address tag whenever the respective member of the union is assigned a
value.