AVR-LIBC 1.4.0 has added a couple of new defines
for EEPROM and FLASH.  Both that I had defined
in my own code, leading to redefinition warnings.

Here is a code snippet that lets you work around
this type of issue.

By checking the GCC version you can load the
appropriate header files(s) from the correct
directories:

#ifdef __GNUC__

#define __GCC_VERSION__ (__GNUC__ * 10000 \
                               + __GNUC_MINOR__ * 100 \
                               + __GNUC_PATCHLEVEL__)

/* Test for GCC < 3.4.0 */
#if __GCC_VERSION__ < 30400
#include <avr/ina90.h>
#endif

/* Test for GCC >= 3.4.3 */
#if __GCC_VERSION__ >= 30403
#include <compat/ina90.h>
#endif

#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/wdt.h> /* Watch Dog */
#include <inttypes.h>

/* Test for GCC == 3.4.3 */
#if __GCC_VERSION__ == 30403
#define EEPROM __attribute__ ((section(".eeprom")))
#endif
[EEPROM was originally defined in my source code files.]

/* Test for GCC < 3.4.4 */
#if __GCC_VERSION__ < 30404
#include <avr/signal.h>
#include <avr/delay.h>
#define FLASH
[FLASH here is specific to my code, see below.]
#endif


/* Test for GCC >= 3.4.4 */
#if __GCC_VERSION__ >= 30404
#include <util/delay.h>

#undef  FLASH /* Use 'PROGMEM' */
#define FLASH

[FLASH is NULL in the GCC case for me, code not shown here defines it for IAR, so the same
source will build with both IAR and GCC.]

#endif

I put those in a file called compiler.h that I include
with every project, so all compiler issues are localized
to one file.  Makes multiple GCC version and using non-GCC compilers
work with the same source code.

Hope the technique helps someone out...




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to