Go Down

Topic: Help - unable to compile example in flash library using FreeBSD (Read 1 time) previous topic - next topic


I am using avr-gcc 4.5.1 on FreeBSD 7.0 and am unable to compile the example flash_streaming file for the flash library.
The other example file flash_example is compiling though.
The following line
Serial << F("This is a test string");
throws up an error by the compiler which says

flash_streaming.cpp:210:13: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers

I have checked that this line of code after preprocessing is

  Serial << (reinterpret_cast<__FlashStringHelper *>((__extension__({static const char __c[] __attribute__((__progmem__)) = ("This is a test string"); &__c[0];})))) ;

Could someone give me pointers as to whats going wrong?

Coding Badly

Does this compile...

Serial << "This is a test string";


Does this compile...
Serial << "This is a test string";

Yes - I have more details
/////-- Sample code --

FLASH_STRING(big_string, "The quick brown fox\n"); // Compiles

void setup()
    Serial.begin(115200);  //
    Serial  << big_string;   // Compiles
    Serial << F("jumped over \n");  // Does NOT Compile
    Serial << "the lazy sleeping dogs";    // Compiles

////////The pre-processed output is shown below
static const char big_string_flash[] __attribute__((__progmem__)) = "The quick brown fox\n"; _FLASH_STRING big_string(big_string_flash);;

void setup()
    Serial << big_string;
    Serial << (reinterpret_cast<__FlashStringHelper *>((__extension__({static const char __c[] __attribute__((__progmem__)) = ("jumped over \n"); &__c[0];}))
    Serial << "the lazy sleeping dogs";

////// Compiler error
tst.cpp:9:15: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers


Are you using Arduino 1.0?

Yes - the only difference from the stock arduino-1.0-linux.tgz is that I have added makefiles to ease compilation, and patched Print.h according to the instructions in Flash/patching_print.txt


Apparently, whatever code supports the << operator for serial output doesn't support __FlashStringHelper.

I'm afraid you'll have to use Serial.print(F("String")); instead of Serial << F("String");
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


It is not a problem with the flash library as the << works in general but F() does not - even when used without the flash library.
Serial.print(F("Hello World")); does not work and gives the same error. BTW I am using avr-gcc-4.5.1


Would any special compiler switch be needed by any chance??


This issue appears to be due to a bug in the F() macro declaration in WString.h
More details in this post

Go Up