code is wrong mistercat 9th June, 2006 02:54 (UTC)
code fragment in the article about string reversing is just wrong. there is 1) an overflow error, 2) complete misuses of c++ programming language for the particular problem.
code is wrong Kirit Sælensminde 9th June, 2006 03:54 (UTC)
mistercat said

code fragment in the article about string reversing is just wrong. there is 1) an overflow error, 2) complete misuses of c++ programming language for the particular problem.

Thanks for your comment mistercat.

For the overflow, do you mean the int should be a std::string::size_type? That won't necessarily cause an overflow but I think we should certainly class it as a bug nonetheless.

I agree that the solution is clever, but misguided. The problem is that std::basic_string is only suitable for use with writing systems where each char or wchar_t is a complete character. For Unicode this means that we have to make sure that the character type we use is 32 bits wide. Normally a massive waste of computer memory. Other encoding systems can't be reliably manipulated at all. Another reader sent me a link to a post by Nathan Myers describing the limitation on the C++ string types.

In FOST.3™ we've ducked around it by implementing a FSLib::wstring that knows it is a UTF-16 sequence and behaves accordingly. The interface is (almost) identical to that for std::wstring.


To join in the discussion you should register or log in
code is wrong mistercat 9th June, 2006 15:01 (UTC)
Kirit Sælensminde said
mistercat said

code fragment in the article about string reversing is just wrong. there is 1) an overflow error, 2) complete misuses of c++ programming language for the particular problem.

Thanks for your comment mistercat.

For the overflow, do you mean the <code>int</code> should be a <code>std::string::size_type</code>?

Yes, I I meant that.

That won't necessarily cause an overflow but I think we should certainly class it as a bug nonetheless.

You're right, it will not cause an overflow if the length of the string is less than or equal to the maximum size of int type.

I agree that the solution is clever, but misguided. The problem is that <code>std::basic_string</code> is only suitable for use with writing systems where each <code>char</code> or <code>wchar_t</code> is a complete character.

Right.

For Unicode this means that we have to make sure that the character type we use is 32 bits wide. Normally a massive waste of computer memory. Other encoding systems can't be reliably manipulated at all. Another reader sent me a link to a post by Nathan Myers describing the limitation on the C++ string types.

In FOST.3™ we've ducked around it by implementing a <code>FSLib::wstring</code> that knows it is a UTF-16 sequence and behaves accordingly. The interface is (almost) identical to that for <code>std::wstring</code>.

Nice!

code is wrong exold 20th April, 2007 07:57 (UTC)
BTW, your comment / question (Ooze…or is it Exold?) nagged at me for a long time. I finally decided that it was worth fixing. Now it's just Exold :). Thanks for mentioning your confusion. I'm happier with the result.
code is wrong Kirit Sælensminde 20th April, 2007 08:06 (UTC)
exold said

BTW, your comment / question (Ooze…or is it Exold?) nagged at me for a long time. I finally decided that it was worth fixing. Now it's just Exold :). Thanks for mentioning your confusion. I'm happier with the result.

Fixed now. Thanks for taking the time to drop by :-)


To join in the discussion you should register or log in