0

I need to see what is happeing under the hood before compilation. How? The following is an example out of many...

I am compiling the Intel Math Lib and that works fine. There are different options to get it running that influence how symbols are defined during precompilation.

I can deduct from the "build code" (make/cmake), what should happen, but my expectations don't match the results. Therefore I would now like to "look into it" and see what actually happens.

Example (simplyfied from bid_conf.h in the mentioned Intel library): The client code using the math library calls this:

num_to_string(s, num);

The code that defines num_to_string is defined further up during precompilation:

BID_EXTERN_C void bid128_to_string (char *str, BID_UINT128 x _EXC_FLAGS_PARAM);

Now _EXC_FLAGS_PARAM is evaluated depending on build arguments, defined here:

#if !DECIMAL_GLOBAL_EXCEPTION_FLAGS
#define _EXC_FLAGS_PARAM , _IDEC_flags *pfpsf
#else
#define _EXC_FLAGS_ARG
#endif

That reads: If the exception flags are not set, then _EXC_FLAGS_PARAM becomes ", _IDEC_flags *pfpsf" or else "" (nada).

The flag is? set but I still get:

error: too few arguments to function call, expected 3, have 2
  num_to_string(s, num);

So _EXC_FLAGS_PARAM becomes ", _IDEC_flags *pfpsf". But DECIMAL_GLOBAL_EXCEPTION_FLAGS is set!...

...or is it not?

How can I print out what is actually set while it is happening, like:

#please_print_this(DECIMAL_GLOBAL_EXCEPTION_FLAGS)

Or even better: see the intermediate output, basically what the compiler ultimately gets fed with...

(No C compiler expert but could not find an answer yet).

raoulsson
  • 14,978
  • 11
  • 44
  • 68

1 Answers1

1

If you're using gcc, compile with the -E option. That will run just the preprocessor and output the result to stdout. Then you can see what the macros expand to.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • Thank you dbush. That is what I need. Trying to get make to pass that in as run arg. Currently got: `make CC=gcc CALL_BY_REF=1 GLOBAL_RND=1 GLOBAL_FLAGS=1 UNCHANGED_BINARY_FLAGS=1`. Tried `make CC="gcc -E" ...`, no luck yet but getting there. – raoulsson Jun 04 '22 at 03:11
  • @raoulsson Don't worry about `make`, since you can't really use the result. Just run the gcc command manually and see what you get. – dbush Jun 04 '22 at 03:12
  • 1
    @raoulsson You'll want to run the `make` command with verbose output e.g. by using `cmake --build ... --verbose`. This should print the command used for compilation of the source file to the console allowing you to add the `-E` option leaving everything else untouched. – fabian Jun 04 '22 at 08:06