Author Topic: Error with F() in WString.h  (Read 5096 times)

mr_bump

  • Newbie
  • *
  • Posts: 2
Error with F() in WString.h
« on: January 13, 2015, 04:06:58 am »
I'm trying to get the wifi shield to work. In the examples, the syntax F() for storing strings in the flash memory is used.
While compiling I get the following error. Any suggestion how to solve this?
Thanks!


Code: [Select]
Arduino: 1.5.8 (Windows 8), Board: "Digispark Pro (16 Mhz)"

Build options changed, rebuilding all

In file included from C:\Users\Simon\Documents\Arduino\hardware\digistump\avr\cores\pro/Arduino.h:221:0,
                 from sketch_jan13b.ino:2:
sketch_jan13b.ino: In function 'void setup()':
C:\Users\Simon\Documents\Arduino\hardware\digistump\avr\cores\pro/WString.h:41:88: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers
 #define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal)))
                                                                                        ^
sketch_jan13b.ino:4:3: note: in expansion of macro 'F'
Error compiling.

digi_guy

  • Jr. Member
  • **
  • Posts: 87
Re: Error with F() in WString.h
« Reply #1 on: January 13, 2015, 07:46:31 am »
Hard to say without knowing what the code was that generated the error.

But based on my past mistakes it looks like you're trying to pass a variable to F instead of a string. I have no idea why but writing something like:
Code: [Select]
String msg = "this string works";
Serial.println(F(msg));

You'll get an error like what you see. If that's the case just use the regular Serial.println(msg) instead of adding in the F() part.

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Error with F() in WString.h
« Reply #2 on: January 13, 2015, 12:32:48 pm »
The 'const char*' in the error message suggests that the value fed to F() is already statically stored another way.  So either another variable or storage mechanism not compatible raw text.

I got this alternate method working that like F() stores strings in the code space and pulls them out with relative ease.
http://digistump.com/board/index.php/topic,1656.msg7703.html#msg7703

mr_bump

  • Newbie
  • *
  • Posts: 2
Re: Error with F() in WString.h
« Reply #3 on: January 14, 2015, 03:56:20 am »
Thanks for the responses. The code I used was a part of the one you find in the examples -> Digispark_Examples -> WiFiServerExample.

Anyway, I found the reason for my problem: I had an older copy of the libraries within the sketchbook folder. I don't know how I created it. But now after deleting it, the code compiles.