Monic Polynomial wrote:
> On 02/06/2009, at 12:12, Martin Costabel wrote:
>> The most difficult thing was to find out how to print the value of a
>> macro at a given moment. From a diving expedition into the depths of
>> the
>> docs, I brought home some macros that give the following small example
>> program in C:
>>
>> #include <stdio.h>
>> // stringify the value of a macro for printing
>> #define str(x) #x
>> #define xstr(x) str(x)
>> // play with replacing macros
>> #define OLD_DEBUG 1
>> #define DEBUG OLD_DEBUG
>> int main(){
>> printf("Before: %s\n", xstr(DEBUG));
>> #undef OLD_DEBUG
>> printf("After : %s\n", xstr(DEBUG));
>> return(0);
>> }
>>
>> If you compile and run this, it prints
>>
>> costabel% ./a.out
>> Before: 1
>> After : OLD_DEBUG
>>
>> I don't know enough to say that there are no analogues of \edef or
>> \let,
>> but I haven't come across them yet.
>
>
> Martin,
>
> You may use GCC flags -E and -dD to achieve that in compile-time
> rather than run-time. For example,
>
> gcc -E -dD program.c -o program.e
>
> outputs program.e, the post-processed version of program.c. -E tells
> gcc to preprocess the file but not compile/build it, and -dD tells gcc
> to output the values of macros.
Yes, this is true, and I used in fact the -E flag in order to find the
origin of that bug. But in practice, this is rather useless if you want
to know what the value of a certain macro is at a certain point in the
program.
Consider the case where I replace in my little program above the line
#undef OLD_DEBUG
by
#include <QtGui/qmacdefines_mac.h>
(This gives the same effect).
Then the command `gcc -E -dD program.c -I/sw/lib/qt4-mac/include` spits
out 1286 lines of code, and among these, the value of DEBUG is only
visible because of the printf statements. If they weren't there, you
would have no chance of seeing that DEBUG=1 before the call to
#include<...> and DEBUG=OLD_DEBUG after that call.
What would be needed is a kind of gdb for the preprocessor stage, where
you can single-step through the program and at each line ask for the
values of all variables and macros. No idea if such a thing exists
(maybe in xcode?).
--
Martin
--
Martin
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Fink-devel mailing list
[email protected]
http://news.gmane.org/gmane.os.apple.fink.devel