Keith Thompson wrote:
"a" <a@mail.com> writes: In .C or .h file we have #define some constant.
While using the gdb debugger, how to show the value of these constant?
We don't know; that's not a C question. gdb comes with extensive
documentation. If that doesn't help, you might try the gnu.utils.help
newsgroup.
Actually, I'll argue that it is topical, in that it touches on what
happens to preprocessor macros when code is compiled.
To the OP: remember that preprocessor macros are simply text
substitutions to make your life as the coder a little easier; during
preprocessing, they are expanded into the replacement text, and that
replacement text is what's fed to the compiler.
For example, take the following code fragment:
#define SIZE 10
void foo(void)
{
int arr[SIZE];
...
}
After the preprocessing stage, all occurrences of SIZE are replaced by
the text "10", as below:
void foo(void)
{
int arr[10];
...
}
This is the text that is actually fed to the compiler; the preprocessor
symbol SIZE no longer exists. Therefore, I would not expect it to be
accessible from a debugger.
Now, specific compilers may allow you to preserve that information for
debugging purposes, but that's beyond the scope of the C language.
FWIW, my experience with gdb leads me to say "you can't do that."