views:

129

answers:

1

I'm programming in C and using Source Insight.

I have an enum type with a lot of constants (like 100). I have debug prints that print out variable values, but they (of course) print out as integers.

What I'd like to do is click on the name of an enum constant, and see its numeric value displayed somewhere. (I've seen this done in a Visual Studio plugin, so it must be possible.)

That is, assume I have

enum colors {
    ORANGE, PURPLE, PINK
};

I want to click on (or select, or something) PURPLE and see the value 1 somewhere visible (ideally, the symbol window or context window, but I'm not particular).

Is there an easy way to do this in Source Insight? Is there a difficult way, at least (such as writing a macro)?

+1  A: 

The only way I've found to do this is to give each member of the enumeration a specific value - then it shows up in the context window when it finds the enum constant. eg:

enum colors {
    ORANGE = 0,
    PURPLE = 1,
    PINK = 2
};

It's not great but it works...

It looks like it would be possible to write a macro that popped up a message box with the value but I can't get it to work properly in 3.50.0064 - it seems to think the wrong enum is under the cursor. My test macro code is

macro ShowEnum()
{
  symbolname = GetCurSymbol()
  symbol = GetSymbolLocation(symbolname)

  if (symbol == nil)
    Msg (symbolname # "not found")
  else
    Msg (symbolname # " found")
}

For me, this returns a random item from the enum list as the "found" one. If returned the right one we could look up the parent with SymbolParent() then iterate through the children using SymbolChildren() / SymListCount()

peter_mcc
@peter--this means that there's no direct way to get the value? In a case of `orange, purple = 42, pink`, then orange should be 0 but pink should be 43. Also, FWIW, the existing code base is huge, plus I don't even have write permissions for the whole thing, so adding the values is impossible (not to mention that later inserting an enum will require re-numbering, aargh).
JXG
Perhaps contact Source Insight support and see if you can get them to fix the bug in the code above. They still issue occasional patches so while, as an evolving product it may be dead, it is still being looked after.
peter_mcc