Possible <SD.h> library bug with __FlashStringHelper

I get a compilation error when SD.h is included that does not occur when it is not included.

I created a small example to show the problem.

The routine is declared:

void sayhi(const __FlashStringHelper *string){}

and called with:

sayhi(F(“F() argument”));

getting a compile error with the SD.h include and no error without the include.

A complete example is attached.

I am using version

C:\Users\mnewm\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.1\libraries\SD

foo.ino (1.2 KB)

I don't know why SD.h triggers if but it looks like the "F()" macro on the ESP8266 doesn't do anything. Possibly the FLASH and SRAM are in the same address space so there is nothing to do.

If you want to compile this sketch for both AVR and ESP8266, add a version that takes "const char *":

void sayhi(const char *string)
{
  Serial.print(F("sayhi type const char * called with: "));
  Serial.println(string);
  return;
}

That seems to eliminate the error by accepting the "const char *" passed.

Something not quite documented is going on. F() does something on ESP8266.

My historical experience is that my code got smaller when I started using F(). This may have been improved in later versions of the tools. Current results show no difference as mentioned by John Wasser.

Perhaps NOW there is just a different datatype that results in different code but no longer gets different storage for the string.

I added code to try a number of things. The code is smaller when Serial.println is never called with an argument that looks like (“foo”). Once there is such a call it does not seem to change the space allocated if Serial.println is called with the F(“foo”) form or the (“foo”) form.

I attach the example expanded to the various forms and the space reported when each is enabled individually. I turned off the error producing inclusion of SD.h in this version for the space analysis and did not have the (const char *) form of sayhi enabled.

As John Wasser suggests compilation with the SD.h inclusion succeeds when an additional sayhi function declaration with argument type (const char *) is added. When both forms of the sayhi function are present AND SD.h is included sayhi(F(“foo”)); calls the (const char *) function. When SD.h is not present it calls the (const __FlashStringHelper *) version.

In case it helps my complete development environment setup is documented at:

http://www.dragonnorth.com/logger/releases.php

All of the details are likely not required for this example.

foo.ino (3.03 KB)