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   |
|
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 
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 
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Fri Jul 18 07:34:07 CEST 2025
Total time taken to generate the page: 0.04091 seconds
|