1

i want to see output of Preprocessor calculating. Only with strings it works so:

#define XSTR(x) STR(x)
#define STR(x) #x

#define BEGIN "test"

#pragma message ".text= " XSTR(BEGIN)

when i set BEGIN to 32/2 the output is: #pragma message: .text= 32/2.

What can i make to solve this? I don´t won´t solutions like this to search in the .lss file:

uint16_t x = BEGIN;
PORTB = x>>8;
PORTA = x;

Thank you.

Umbrecht
  • 35
  • 6

2 Answers2

2

What can i make to solve this?

You have to implement math operations in the preprocessor. For example:

#define _div_1_over_1  1
#define _div_2_over_1  2
#define _div_3_over_1  3
// etc...
#define _div_30_over_2  15
#define _div_31_over_2  15
#define _div_32_over_2  16
// etc...
// etc. for every possible a_over_b combinations, many many 1000 lines
#define DIV(a, b)  _div_##a##_over_##b

After that, you finally can:

#define XSTR(x) STR(x)
#define STR(x) #x

#define BEGIN DIV(32, 2)

#pragma message ".text= " XSTR(BEGIN)

Let's say this is one way of implementing division in preprocessor. For other solutions, see BOOST_PP_DIV and P99_DIV from p99 library.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
1

The C preprocessor just performs text replacement(s).

The first opportunity to see folded constants is in the tree dumps with -fdump-tree-all and then inspect the *.t<nnn> dumps.

To get the asm output from the compiler proper, try -safe-temps -fverbose-asm which inserts C source intermingled as asm comments in the *.s file.

emacs drives me nuts
  • 2,785
  • 13
  • 23