Keith Thompson said:
The first thing you should do is learn how to post proper followups
(this is in reference to your other followups in this thread). Don't
assume that everyone can see the article to which you're replying.
You need to provide some context, as I've done here, so each article
can be read on its own. Google makes it gratuitously difficult to do
this, but there is a workaround (that's been posted here over 1000
times).
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
As for your question, the answer is that there's no way to do what
you're asking with macros, because that's not what macros are for.
You can build a table mapping strings to numbers, and look up and
display which strings (if any) are mapped to a specified number; it
just doesn't make any sense to use macro definitions for this purpose.
What are you really trying to accomplish, and why do you think that
macro definitions should be part of the solution?
I have done something like what OP is asking about when learning
Windows programming, to watch Windows messages and have their
macro names visible (e.g. 'WM_PAINT', 'BN_CLICKED', etc.).
I created a little utility that scanned the appropriate headers
and created a C source file containing tables which associated
the macro names to their values, and #included that in my application.
There are existing 'Spy' programs that can do this message watching
(one comes with VC++), I did mine so that I could integrate the 'spying'
with the application rather than switching between it and a separate 'spy'
program, and admittedly also for fun.
Later I added this table building to the application logic itself, making
it 'dynamic' (searching the headers and adding table entries as needed
during lookup).
Doing things like this does have an inherent 'fragility', as headers can
change (and/or change locations/availability) over time, so one must
ensure the availability (and correct version) of the headers, and make
sure the same header is used during compilation and execution. Then
there are the issues of macros inside #if/#endif etc. and those inside
comments. It would be quite a large chore to take all that into account,
I only went as far with that as needed to meet my immediate needs
(IOW "I cheated a bit"
)
Elsethread folks warned about e.g. macros defined in terms of others
(that did happen a bit with my specific example), and different macros
producing the same values. So of course context must be considered (e.g.
in my example, many of the Windows control notification macros have the
same values, so lookup of the correct macro needs more context information
(such as a window class name).
Anyway, my point is that while it's 'uncommon', I don't think what OP
wants is completely unthinkable.
But as you say, we need OP to state a specific problem in order to
offer the most appropriate advice.
-Mike