Search code examples
ccompilationpragma

C pragma that writes text into a file during compilation


Is it possible to write text into a file during compilation?

For example:

#ifdef ICC
#pragma write("log.txt", "ICC was used to compile %s", __FILE__)
function_optimized_for_icc()
#endif

Solution

  • Not that I know of, but in most compilers you can easily use a pragma to write a message to the console (#pragma warn, #pragma message etc.).

    At that point you can just > redirect or tee the output to a file and filter it appropriately.