I'm new to C programming so please help a fella out. When compiling I'm getting a "invalid initializer" problem.This is the relevant code.
void lcd_writePString(char const* string) {
char c;
while ((c = (char)pgm_read_byte(string++)))
lcd_writeChar(c);
}
void os_errorPStr(char const* str) {
SREG &= 0b10111111; //Interrupts global deaktivieren
lcd_clear();
lcd_writePString(PSTR(str)); //THIS IS WHERE THE COMPILER THROWS OUT THE ERROR
while (os_getInput()!=0b10000001){
os_waitForInput();
}
lcd_clear();
SREG |= 0b01000000;
}
So why does my compiler throw out the error "invalid initializer"? The PSTR thing writes the string onto the flash memory of my micro controller.
This is what PSTR does:
/** \ingroup avr_pgmspace
\def PSTR(s)
Used to declare a static pointer to a string in program space. */
# define PSTR(s) ((const PROGMEM char *)(s))
#else /* !DOXYGEN */
/* The real thing. */
# define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
#endif /* DOXYGEN */
lcd_writePString expects a
char const*
yet you cast the parameter toconst PROGMEM char *
through some obscure macro. Either don't cast it to this type or change the prototype of lcd_writePString.