custom string class or use std::string?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I try to use standard libraries whenever I can (until I run out of memory). I just found out that the avr-libc implementation of string.h doesn't include the "string" type (no class), and am wondering what you Freaks usually do.

Do you write your own little class, or use std::string, to get string::string()?

I hate counting characters.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But std::string is C++, not C. Avr-gcc does not have any of the C++ libraries.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tlucas wrote:
I try to use standard libraries whenever I can (until I run out of memory).

Me too.

tlucas wrote:

I just found out that the avr-libc implementation of string.h doesn't include the "string" type (no class), and am wondering what you Freaks usually do.

"string.h" is a C header. "string" class is in a C++ header called "string" - and like said above avr-libc does not have C++ libraries.

tlucas wrote:

Do you write your own little class, or use std::string, to get string::string()?

I hate counting characters.

Well, why do you need to count characters? And if you need to, strlen or something similar will work. Most likely you won't need all the functions the "string" class would provide, after all your AVRs have only few kilobytes of SRAM, and strings in flash never change.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I second ( third ) the motion to use standard libraries when possible and to that end, on a lark, I wrote a simple fixed length std::string-like class. It is nice in some ways but I have to agree with the above; on the AVR, strings tend to be fixed and short. There is really little need for a string class. In those cases where a string class would be nice, you often find yourself overstepping the bounds of memory anyway. So I ( granted I do precious little with strings in my applications ) tend to simply use character arrays and minimal C string functions.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."