_EXFUN compiler error Arduino Due

I'm working on a code for a friend. I'm using a Mega en he is using a Due.

The below code is the minimum example that throws an error on the Due but no error on the Mega.

uint16_t index;

void setup()
{
  // put your setup code here, to run once:

}

void loop()
{
  // put your main code here, to run repeatedly:

}

The error

sketch_jan03a:1: error: 'uint16_t index' redeclared as different kind of symbol

 uint16_t index;
          ^

In file included from c:\users\sterretje\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\stdlib.h:11:0,
                 from C:\Users\sterretje\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:24,
                 from sketch\sketch_jan03a.ino.cpp:1:

c:\users\sterretje\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\string.h:55:8: error: previous declaration of 'char* index(const char*, int)'
 char  *_EXFUN(index,(const char *, int));
        ^

Some research shows that this problem is not limited to the Due; see e.g. Getting error message 'DS3231 clock' redeclared as different kind of symbol' where (part of) the error for a NodeMcu is

C:\Users\seamr\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/libc/xtensa-lx106-elf/include/../include/time.h:50:19: error: previous declaration of 'clock_t clock()'

clock_t _EXFUN(clock, (void));

So certain 'names' (index, clock) seem to cause a conflict and the big question is what those 'names' are. Anyway to find it?

I guess you got used to not declare a function or variable under the name strcpy, I guess it goes along the same line, you need to know on your platform what are the standard functions names that are readily available and not use them.

if I remember well the _EXFUN thingy is a macro used in some headers (that will get activated on some platforms) to deal with some of the name mangling of C++ and legacy C stuff . You could also set the macro to something else during coding.

For example the macro is defined here in ESP-IDF

#define	_EXFUN(name, proto)		__cdecl name proto

and then used throughout the headers files

You'll find that index() is one of those functions that gets exported as part of some standard extensions

Thanks, I never knew that there was a life outside the standard :smiley:

Crazy isn’t it ? What were they thinking :slight_smile:

The good thing speaking another language than English and using that for your variables keeps you out of trouble. We would use indice in French instead of index

As said, I'm helping a friend. We're both Dutch (and basically fluent in English); he used Dutch variable names and I have renamed them all to English :frowning:

:slight_smile: too much of a good thing !

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.