"Partition Type Conflict" Due to Macro Definition in GCC 4.8.2

I get a section type conflict if I call a macro in an inline function. There is nothing to learn about this error on the WWW.

The purpose of the macro is to propose a macro for working with strings stored in a flash for Arduino (side information only). If the function is not built-in, everything is in order. What could be the reason?

#undef PROGMEM #define PROGMEM __attribute__(( section(".progmem.data") )) #undef PSTR /* need to define prog_char in avr-gcc 4.7 */ #if __AVR__ && __GNUC__ == 4 && __GNUC_MINOR__ > 6 typedef char prog_char; #endif /* 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); \ (prog_char_t *)&__c[0]; })) #endif 

the code:

 inline void test() { hal.console->println("AP_Common tests\n"); hal.console->println_P(PSTR("AP_Common tests\n") ); hal.console->printf_P(PSTR("AP_Common tests\n") ); } void setup(void) { test(); } void loop(void) { // do nothing } 

Errors for: "println_P (PSTR (" Bad var table \ n "));"

 AP_HAL/utility/BetterStream.h:53:57: note: in definition of macro 'printf_P' #define printf_P(fmt, ...) _printf_P((const prog_char *)fmt, ## __VA_ARGS__) ^ output_debug.h:13:26: note: in expansion of macro 'PSTR' hal.console->printf_P( PSTR("{\"t\":\"s_cmp\",\"h\":%.1f}\n"), ^ AP_Progmem/AP_Progmem_AVR.h:25:56: note: '__c' was declared here #define PSTR(s) (__extension__({static const prog_char __c[] PROGMEM = (s); \ ^ AP_HAL/utility/BetterStream.h:53:57: note: in definition of macro 'printf_P' #define printf_P(fmt, ...) _printf_P((const prog_char *)fmt, ## __VA_ARGS__) ^ AP_test.ino:60:27: note: in expansion of macro 'PSTR' 

EDIT:

Calling PSTR () in twice derived classes causes the same problem. I think this is a compiler error, which leads to undefined behavior.

+2
c arduino
source share
1 answer

try: PROGMEM static const prog_char __c[] . It is strange that I found out that the attribute must precede the declaration. Not sure what your version is doing. This can be a problem.

Alternatively: A partition type is an attribute of a logical memory partition in which values ​​are stored. I suppose this was reported by the linker. The PROGMEM section by default is NOLOAD (which makes sense for this section). However, due to initialization, the compiler requires the section to be the opposite, resulting in an error. Even if this is not true, I would look for a problem in this area.

Some additional notes:

  • use stdint types, don't rely on built-in types for their size.
  • Be careful with 'char'. Use only for actual characters and do not rely on your signature. If you need to take care of another type (uint8_t or int8_t), it will be more appropriate.
  • `#undef 'not before using them, but after necessary. Otherwise, inadvertent redefinition may fail without warning. These errors can be very difficult to debug! Instead, use protective devices in the headers.
  • In microcontrollers, constant correctness is important, so use it wisely. Do not avoid const , even if it requires more effort (until you get more experience). This will not only reveal a common flaw during compilation, but also save RAM and (possibly even) Flash, since non-constant variables are stored in RAM with initialization values ​​in Flash.
  • Do not use __ -prefixes in custon code. They must be reserved for the compiler and toolchain system libraries). You can use this as a suffix, though (but why in the example?)
  • Avoid casting. Most throws in the code for beginners are practically not needed or are a sign of poor interface design. Basically: if you do not need to specify the type of the function argument, then the type is not required. (Yes, there are exceptions - that’s why I call it the basic rule, not the law).
  • In general: use all the help from the compiler you can get. Built-in debugging is not very funny.
+2
source share

All Articles