Although I do not really plan on using double, I would like to understand why this is a problem.
#include <stdint.h> #include <avr/io.h> #include <util/delay.h> double y[1] = {2.0}; // doesn't work //static double y[1] = {2.0}; // works //uint8_t y[1] = {2}; // works int main(void) { DDRB |= 1 << DDB1; while(1) { if( y[0] > 0) { PORTB ^= 1 << PORTB1; } _delay_ms(1000); } return 0; }
The code above does not compile for the ATtiny4. I try to compile with avr-gcc and options -mmcu=attiny4, -Os, and -DF_CPU=1000000UL. The compiler balks with the following message
/usr/local/Cellar/avr-gcc/6.2.0/lib/gcc/avr/6.2.0/../../../../avr/lib/avrtiny/libm.a(gesf2.o): In function `__gesf2':
(.text.avr-libc.fplib+0x0): undefined reference to `__fp_cmp'
collect2: error: ld returned 1 exit status
The optimization level does not seem to have any affect on it. Changing the declaration of the array y to one of the following fixes things.
static double y[1] = {2.0};
or
uint8_t y[1] = {2};
It also works if y is passed to a function.
#include <stdint.h> #include <avr/io.h> #include <util/delay.h> double y[1] = {2.0}; void update(double *y) { y[0] = 2.0; } int main(void) { DDRB |= 1 << DDB1; while( 1) { update(y); if( y[0] > 0) { PORTB ^= 1 << PORTB1; } _delay_ms(1000); } return 0; }
What accounts for these behaviors? Why are things so? Thanks.