Char arrays? Or, String objects?


#1

Old c developer here… Used to c arrays, pointers, strcmp() and other age-old methods of handling strings. I was scared by the String.h issues in arduino. Speed, memory, bla bla bla.

So… What is the preferred method for handling strings in the Particle Photon world? Is it necessary to switch from classic string handling to an string object?

And if I CAN stay with classic string handling, where are all the header files with prototypes of things like strcmp() , etc.

(Currently using the [genius?] po-util environment by Nathan Robinson to keep all my builds local to my mac.)

There has got to be a FAQ or tutorial on string handling somewhere for Particle devices.


Moving project from Web IDE to Particle Dev on a Mac
#2

I generally prefer to use the standard C/C++ libraries for the reasons you mentioned.

The reason string.h and the rest of the standard C and C++ libraries don’t show up when you search the firmware repository is that they’re provided by the gcc-arm compiler toolset. So wherever you’ve installed your gcc-arm compiler to, that’s where you’d need to search.

It’s a pretty standard gcc C++ compiler running in C++11 mode. The cloud compilers currently use 4.9-2015-q3, I think.


#3

Still looking for it under Nathan’s po-util.

Can’t find it. Trying to

find /Users//github -name “string.h” -print

But nothing.


#4

The compilers should have been added to your PATH. Try:

which arm-none-eabi-gcc

#5

These are not part of po-util but the GCC toolchain, hence the headers will be there (as @rickkas7 indicated above).
But since we are dealing with C++11 you can look anywhere else too
e.g. http://www.cplusplus.com/reference/

And if you want to look at the implementation of the Wiring String class, you may want to look in the Particle repo
e.g. https://github.com/spark/firmware/blob/develop/wiring/inc/spark_wiring_string.h


#6

The Particle firmware is located in ~/github/firmware.

application.h is located in ~/github/firmware/user/inc

You would have found spark_wiring_string.h if you did:

$ find ~/github/firmware -name "*string.h" -print

#7

I’m a hobbiest programmer and dip in and out of many languages including Java, VB, C, and Ruby. All apart from C have native String libraries and previous to Particle making their Strings library I wrote my own functions to perform indexOf and Substring. As I’m not a professional programmer I would assume that as a professional programmer wrote the String.h library it’s going to be much better then anything I would write, so I prefer to use it. Makes my code much simpler and I haven’t had any issues.


#8

The thing about professional code is that it still can be used in an unprofessional manner.
Ease of use often comes with some caveates (e.g. heap fragmentation for String) which need to be considered when deciding for one over the other.
C char[] strings are native to that language - despite the lack of a keyword for that - and since C++ is a direct descendent of C these are still native to C++ too and all the functions for that are also written by pros.