U++ framework
Do not panic. Ask here before giving up.

Home » Community » Newbie corner » Search for constant and show it....
Re: Search for constant and show it.... [message #36193 is a reply to message #36178] Thu, 10 May 2012 14:36 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1796
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

If you are allowed to modify the code defining the constants, you can use some preprocessor trick, e.g.:
#ifndef flagDEBUG
#define CONSTVAL(NAME,VALUE) const uint16 NAME = VALUE
#else
VectorMap<int,String> const_values;
#define CONSTVAL(NAME,VALUE) const_values.Add(VALUE,#NAME); const uint16 NAME = VALUE
#endif

namespace CanMethod
{
CONSTVAL(PING_REQUEST, 1001);
CONSTVAL(PING_REPLAY, 1002);
CONSTVAL(DEVICE_STATE_REQUEST, 1003);
CONSTVAL(DEVICE_STATE_REPLAY, 1004);
}

It defines the constants using a macro, just if it is in debug mode, it adds each value to a "dictionary", which you can later simply query like const_values[1003] to get string description "DEVICE_STATE_REQUEST", which is what you want if I understand correctly Smile

There also might or might not be a way to do this using debug informations present in the executable. You could probably hack some solution using gdb or some of its code... But it is certainly too much work to even think of it Wink

Best regards,
Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: XML exercise
Next Topic: time measurement :: RTIMING, TimeStop, GetTickCount
Goto Forum:
  


Current Time: Wed Apr 29 09:17:46 GMT+2 2026

Total time taken to generate the page: 0.00693 seconds