#ifdef SAMD_SERIES does not work for the Due, but #ifdef __SAM3X8E__ does (??)

hi,
I tried to use dtostrf() for the Due, so I tried

#ifdef SAMD_SERIES
#include "avr/dtostrf.h"
#endif

which did not work (error: 'dtostrf' was not declared in this scope),
but

#ifdef SAM3X8E
#include "avr/dtostrf.h"
#endif

worked (IDE 1.8.8 ):

    char buf[40];  

    Serial.print("dtostrf test ");
    dtostrf(3.456, 7, 4, buf);
    Serial.println(buf);

what am I missing?

is there perhaps a macro #define which targets either ARM Cortex board?

dtostrf() works if you add its definition ( I don't know why this is not already in Wstring.h):

char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}
void setup() {
  // put your setup code for core 0 here, to run once:
  Serial.begin(250000);
  char buf[40];

  Serial.print("dtostrf test ");
  dtostrf(3.456, 7, 4, buf);
  Serial.println(buf);
}

void loop() {

}

my point is not just about dtostrf, instead it's a general issue about SAMD_SERIES.

I need to have this preprocessor directive also for different other source codes.

So what am I missing about SAMD_SERIES ?

is there perhaps a macro #define which targets either ARM Cortex board?

By "either ARM Cortex board", do you mean the Due and the Arduino SAMD Boards?

If so, you can do this:

#if defined(__SAM3X8E__) || defined(__SAMD21G18A__)

yes, that’s what I do currently.
I’m using M0/Zero, M3/Due and Adafruit M4.

But no macro which works for all ARMs?

"All ARMs" covers a lot of ground. I don't know of a standardized macro to identify any microcontroller that uses an ARM core. However, if you want a single macro that will match the Due, any of the Arduino SAMD Boards, and any of the Adafruit SAMD boards, as well as any other of the SAM chips, you can use the SAM macro.

thank you, that seems to work!

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per