C++ warning with PROGMEM (4.2.2)

Go To Last Post
55 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mihlit wrote:
#define __GNUC_PATCHLEVEL__ 3
#define __GNUC__ 4
#define __GNUC_MINOR__ 3
Don't do that, except you want to confuse headers and yourself. This are built-in defines in GCC. You can test them, but overriding them is discouraged.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Don't do that,

Don't worry, he's just re-quoting the "-E -dM" output I showed above. It's the compiler, not him making the defines.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:
mihlit wrote:
#define __GNUC_PATCHLEVEL__ 3
#define __GNUC__ 4
#define __GNUC_MINOR__ 3
Don't do that, except you want to confuse headers and yourself. This are built-in defines in GCC. You can test them, but overriding them is discouraged.

I did not mean that I'm going to override them. I'm going to use them.

#if (((__GNUC__ * 1000) + __GNUC_MINOR__) * 1000 + __GNUC_PATCHLEVEL__) < 4006002
# ifdef __cplusplus
#  undef PROGMEM
#  define PROGMEM __attribute__(( section(".progmem.data") ))
#  undef PSTR
# endif
#endif

#if (((__AVR_LIBC_MAJOR__ * 1000) + __AVR_LIBC_MINOR__) * 1000 + __AVR_LIBC_REVISION__) < 1008000
# ifndef __PGMSPACE_H_
#  warning "This file should be included after "
# endif
# undef PSTR
# undef PGM_P
# undef PGM_VOID_P
# define PGM_P const char *
# define PGM_VOID_P const void *
#endif

#ifndef PSTR 
# define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s);&__c[0];}))
#endif

This is content of my own header file. It's included after avr/pgmspace.h This should replace PROGMEM definition only for g++ and only for version < 4.6.2. Also it redefines PSTR macro in that case, because it was originally defined with "old" PROGMEM. For (old) avr-libc it changes several definitions, because they are not using const and they are using wrong PROGMEM via prog_* types (obsoleted in new avr-libc version). This works with all avr-gcc [4.3.3,4.6.2,4.7.0] x avr-libc [1.6.7,1.7.1,1.8.0] combinations I've used.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a side note: You just can include avr/pgmspace.h at top of your file and no matter where in the source you place the #include "foo.h" it will work:

#ifndef FOO_H
#define FOO_H
#include 
#undef PSTR
#define PSTR
...
#endif

avrfreaks does not support Opera. Profile inactive.

Pages