char* VectorString::getString(){
const word vecSize = vec.size();
char buf[vecSize] = "\0";
for(word i = 0; i < vecSize; i++) buf[i] = vec[i];
return buf;
Why would you want to? It returns a char pointer but is also Vector class that uses the allocation and deallocation that shotguns your sparse RAM space.
Vector, String and the like are okay for limited use on Arduino. The problems I see are
learning those and not char arrays so which do you use? The one you 'know'.
not 'knowing' what is behind them, what they do leading to cluelessness when the sketch crashes.
You can change "char arrays are suggested" to "char arrays are strongly suggested".
How would I change this function:
The function should take a reference to where to store the result. The caller then should allocate (dynamically or statically) the space where the string is to be extracted to. Of course, that means that the caller is responsible for making sure that the size is appropriate.
for(word i = 0; i < vecSize; i++) buf = vec*;[/quote]*
What the hell is a word? Use standard Arduino types, not some shit invented by those idiots in Redmond.
I do believe that the term word as used in computing originated before Gates was in business.
Even ATMEL uses the term.
I knew machines (were they called computer in those days ?) with word sizes of 12 or 36 bit !
A byte being 8 bit is common sense,
uint16_t is known by rather basic include files to "all" c compilers to get rid of that annoying uncertainly what an int is, when it matters.
But word = uint16_t and dword = uint32_t, might be something you do not need to follow, if you don't want to.
I do believe that the term word as used in computing originated before Gates was in business.
It's size is not obvious, though. int, long, byte, float, double, all have easily remembered sizes. word is some vague typedef'd mess that never should have been allowed. It's far too vague.
A word is not shit. In programming terms, it is a group of bytes. On my Windows Programmer's Calculator, there is an option to choose the [signed] number size in bytes:
Byte (8 bits)
Word (16 bits)
Dword (32 bits)
Qword (64 bits)
In Arduino, it is a short term for unsigned int. http://arduino.cc/en/Reference/Word.
I like using words.
So, do you think that I should just give up on VectorString? Would it be better to have 3 String/string/VectorString objects, or 3 char arrays with 50 character space allocation each? I still want to know what is preventing my VectorString::getString() function from returning a string printable to the Serial Monitor.