AP_Common: PSTR def has specific version for avr-gcc 4.6 compatibility

* Also a small change in FastSerial/vprintf.cpp, which duplicates the
  PSTR definition
* Won't effect others using earlier versions of avr-gcc
This commit is contained in:
Pat Hickey 2012-10-15 19:23:15 -07:00
parent 6b6e580a13
commit def4ffbe86
2 changed files with 11 additions and 0 deletions

View File

@ -94,9 +94,15 @@ typedef struct {
#endif #endif
# undef PSTR # undef PSTR
/* Need const type for progmem - new for avr-gcc 4.6 */
# if __AVR__ && __GNUC__ == 4 && __GNUC_MINOR__ > 5
# define PSTR(s) (__extension__({static const prog_char __c[] PROGMEM = (s); \
(const prog_char_t *)&__c[0]; }))
#else
# define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); \ # define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); \
(prog_char_t *)&__c[0]; })) (prog_char_t *)&__c[0]; }))
#endif #endif
#endif
// a varient of PSTR() for progmem strings passed to %S in printf() // a varient of PSTR() for progmem strings passed to %S in printf()
// this gets the gcc __format__ checking right // this gets the gcc __format__ checking right

View File

@ -52,7 +52,12 @@ extern "C" {
#undef PROGMEM #undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") )) #define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR #undef PSTR
/* Need const type for progmem - new for avr-gcc 4.6 */
#if __GNUC__ == 4 && __GNUC_MINOR__ > 5
#define PSTR(s) (__extension__({static const prog_char __c[] PROGMEM = (s); &__c[0];}))
#else
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) #define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
#endif
#ifdef GETBYTE #ifdef GETBYTE
#undef GETBYTE #undef GETBYTE