Custom TRACE macro and __FILE__.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Newbie here.

I'm trying to write a simple TRACE macro using IAR compiler. It's for a XMEGA 256A3. The macro looks like this (compiled using --string_literals_in_flash).

#define TRACE(x) printf_P("s(d): ", __FILE__, __LINE__); printf_P x

I get garbage because of the __FILE__ symbol. The only way I've been able to use the macro is by assigning __FILE__ to a temporary variable before printing.

char file_name[] = __FILE__;


Why is the temporary variable necessary?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe get the generator to output the pre-processed file to get some idea?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem solved using the following line.

printf_P(__FILE__);