Displaying text in preprocessor

I’d like to include a preprocessor statement which displays the user-defined compile time options selected; i.e. something like
#ifdef USE_LOWER
#echo "User has selected USE_LOWER flag
[some statements]
#else
#echo “User has NOT selected USE_LOWER flag”
#endif

Is there any way of doing this?

Phil

Hi Phil,

I don’t believe there is any way to have the preprocessor do this. What are you trying to accomplish? Perhaps, there might be another method.

  • Mat

It’s nothing fancy, but I’d be nice to remind the user what the flags selected actually do.
I simply want to display something about the code compilation at compile time.

Hi Phil,


While this doesn’t do exactly what you want, you can try using the ident pragma to insert strings into your application’s binary file and then use grep to determine what options were used.

Example:

% cat x.c
#include <stdio.h>

int main () {

#ifdef STR1
#pragma ident "HELLO_STR1"
#else
#pragma ident "HELLO_STR2"
#endif

  printf ("Hello\n");
}
% pgcc -DSTR1 x.c
% grep HELLO_STR1 a.out
Binary file a.out matches
% grep HELLO_STR2 a.out
% pgcc x.c
% grep HELLO_STR1 a.out
% grep HELLO_STR2 a.out
Binary file a.out matches

Hope this helps,
Mat

I think your best solution would be to use the ident pragma with the strings command:

% cat x.c
#include <stdio.h>

#ifdef STR1
#pragma ident "HELLO INFO: STR1 WAS USED"
#else
#pragma ident "HELLO INFO: STR1 WAS NOT USED"
#endif

int main () {
  printf ("Hello\n");
}
% pgcc x.c -c
% strings -a x.o | grep "HELLO INFO"
HELLO INFO: STR1 WAS NOT USED

I should also note that this only works with C/C++.

  • Mat