Pages: [1]   Go Down
Author Topic: Help - unable to compile example in flash library using FreeBSD  (Read 1156 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Does this compile...

Serial << "This is a test string";
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.begin(115200);
    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

Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Are you using Arduino 1.0?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8966
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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");
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This issue appears to be due to a bug in the F() macro declaration in WString.h
More details in this post
http://arduino.cc/forum/index.php/topic,91314.msg735641.html#msg735641
Logged

Pages: [1]   Go Up
Jump to: