0

I'm not widely knowledgable with C++Builder. How do I print some numeric and hex values via compiler message?

#pragma message <text>

I found some example from this link below but it does not seem to be working:

Print numeric value of a define that's based on other macros via pragma message?

Here is an example:

#define __MY_CONDITIONAL_MACROS
#define __MY_NUMERIC_MACROS 0xA00
#define __MY_STRINGS_MACROS "some text"

#ifdef __MY_CONDITIONAL_MACROS
   /* how to print value */
   #pragma message (__MY_NUMERIC_MACROS)  
#else
   /* it's working for char or string */
   #pragma message __MY_STRINGS_MACROS
#endif

/* here an error code to test */
#pragma message __MY_NUMERIC_MACROS
/* [bcc32c Error] activesock.c(44): pragma message requires parenthesized string*/
#pragma message (__MY_NUMERIC_MACROS) 
/* [bcc32c Error] activesock.c(44): expected string literal in pragma message */
#pragma message __MY_STRINGS_MACROS /* OK */
Dicky Tamara
  • 211
  • 2
  • 14
  • 1
    What you showed works fine for me in the "classic" compiler. Are you using the classic compiler, or a CLang compiler? If you are using a CLang compiler, you have to use `#pragma message "text"`, which AFAIK does not expand embedded macros. The `_Pragma` syntax demonstrated in the question you linked to should be able to do that. – Remy Lebeau Jul 17 '19 at 21:54
  • im using Clang compiler, rio version. – Dicky Tamara Jul 17 '19 at 21:59
  • 2
    The `#pragma message ()` syntax only works with string literals (ie `#pragma message ("text")`), it does not allow embedded macros. `#pragma message __MY_NUMERIC_MACROS` works fine in the classic compiler, I don't know if it works in the clang compilers. If not, did you try what the answer to [the question you linked to](https://stackoverflow.com/questions/32388928/) said? `#define STR(x) #x` `#define XSTR(x) STR(x)` `#define MSG(x) _Pragma (STR(message (x)))` `MSG(XSTR(__MY_NUMERIC_MACROS))` This is demonstrated in the [clang documentation](https://clang.llvm.org/docs/UsersManual.html) – Remy Lebeau Jul 17 '19 at 22:24

0 Answers0