converting old c strings to STL

  • Thread starter Sprechen sie von C++
  • Start date
S

Sprechen sie von C++

I have some old code and I was wondering if there is any quick strategy to
convert everything to std::string so that I can make the code compile with
fewer warnings?

Manual work is tedious in the extreme.
 
I

Ian Collins

I have some old code and I was wondering if there is any quick strategy
to convert everything to std::string so that I can make the code compile
with fewer warnings?

What you are asking is verging on the impossible. You have to analyse
every function that manipulates the C style "strings" and convert them.
Manual work is tedious in the extreme.

That depends on how much it pays!
 
J

Jorgen Grahn

If your goal is to have fewer warnings then you should fix the causes of
warnings (probably using const char* instead of char* in most places).

Yes, using C strings doesn't mean you should have compiler warnings;
something else is wrong.
If you want to convert to std::string you can replace all "char *" with
"const std::string&", then fix compiling errors, then fix unit test errors.

Perhaps a bit too naive approach, and I'm pretty sure he has no unit
tests. (You could argue that he should create them, or not rewrite the
code using std::string.)

I'd try it on a piece of the code first -- in some of the classes for
example. And I would first analyze the code for:

- use of C-style casts (gcc can warn for them)
- use of memcpy(), bzero(), memset() and the other functions which
you cannot safely use on objects

/Jorgen
 
J

Jorgen Grahn

Jorgen Grahn ha scritto:


VC by default emits warnings for many C string functions.

Oh. Then I guess it's time to read through them, understand them, and
disable them (in that order).

/Jorgen
 
S

Sprechen sie von C++

I am slowly cleaning up the code, the whole thing is 250K lines of code.
Keeps me busy working anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top