Coming from arduino IDE

Hi There,

is there a reading for ‘moving from arduino ide’? while playing around, I pasted some standard arduino sketches to the webide and got some compiler errors, like:

the_user_app.cpp:21:20: error: deprecated conversion from string constant to ‘char*’ [-Werror=write-strings]

where to get help about converting arduino sketches to spark webide?

Thank you

Pitt

I don’t know of a general answer to your question, maybe one of the Spark guys or other experts can chime in. But I have seen this particular error message when the compiler finds a function that has an argument declared char* but you call it with a constant string:

bool matchMyString(char* searchStr) {
…more code…
}

called as

if (matchMyString(“foobar”) {…

The fix for me was to change the function declaration, but you could change the caller–that would use more RAM.

bool matchMyString(const char* searchStr) {
…more code…
}

const tells the compiler you are not going to change the input argument. It was worried you would try to change the string “foobar” in the caller, which is not writeable.

Hope this helps!

1 Like

hi, yes it pointed me the direction :smile: … thx

pitt

bko is spot on, I was doing the same and having to add the const keyword through much of my converted code initially.

Alternatively you can make the call as follows, but it does come at the expense of an extra line of code and memory for the new variable.

called as

char myCharArray[] = "foobar";
if (matchMyString(myChararray) {...

A better option, that avoids having the change the code and make your char array constant is to flag the GCC compiler to ignore the warning (and thus not get flagged in the :spark: compilation step as an error).

If you include the following pragma at the top of your source code it should compile without the const changes.

#pragma GCC diagnostic ignored "-Wwrite-strings"

Hope this helps.

Cheers
Chris

2 Likes

Thanks for this Chris! I saw you had posted to magic GCC pragma in another thread and meant to come back and repost here too. This will save a lot of time in porting old code.

I will say that have a more strict GCC compiler is not a bad thing and declaring these string args const when you are not changing them is better practice, in general. The only pain comes from having to move other folks old code in to a project.

Thanks again!

1 Like