Electronic – avr-gcc float macro error

atmegaavr-gcccfloating point

When I try to compile some code with macro definition at the following definition

# define _SPEED_FACTOR0 0.9 //or any float value

I get the error

floating constant in preprocessor expression

I am using avr-gcc (version 4.8.2)

here is the full compilation command and the error

avr-gcc -g -Os -mmcu=atmega644p -c test_sens_mot.c ../utils/sources/*.c -I../utils/includes

In file included from ../utils/sources/motors.c:1:0:

../utils/sources/motors.c: In function ‘go’:

../utils/includes/global.h:14:25: error: floating constant in preprocessor expression
# define _SPEED_FACTOR0 0.9 //only on timer 0

I am interested in avoiding this, and still using macros and float values.

thanks!

Best Answer

I got it!

As Dave Tweed suggested in a comment, the issue was not the declaration itself but the way I was using that macro. In other lines I was doing this:

#if SPEED_FACTOR != 1

and if I comment this part everything works fine.

Thanks!