views:

41

answers:

1

Hi all,

i have gone through the numerous questions regarding signed/unsigned char. I understand there are three distinct char types in C++. Currently i have a large code-base which is compiled with Visual Studio - the "default char unsigned" setting is set to "No". Now i'm supposed to add a particular project to our code-base (integrate it to be a part of our current tool-set). This project comes with a documentation where it is strongly emphasized that it needs default char to be unsigned.

Now i began to wonder: why did the author use "char" and not "unsigned char" if he needs char to be unsigned? What could go wrong if i change our code-base to have the "default unsigned char" settings set to "Yes"? And what could go wrong if i change all "char" to unsigned char in the whole project i'm supposed to add to our code-base?

Actually what i should probably ask was "How am I supposed to add this project to our code-base without breaking anything" but that would be asking for a solution and i would not learn anything ;)

+3  A: 

Um, holy crap. Can you tell us where this code came from so we can avoid it? :)

My first instinct would be to build the code as a separate library that your existing project links to, and be careful when you interface with it. Not knowing the exact nature of the code in question, I don't know if that's feasible.

If the code you're bringing in really assumes char is unsigned, you should be OK simply changing it to make it an explicit unsigned char, but that raises the question of whether you're going to have to merge in new versions of the code later, so I'd still prefer the library solution.

Nicholas Knight
+1 for thinking of upcoming releases - the timeline is so easily overlooked...
davka
I'm going for the second option, since the project will be updated - but as a part of our current code base, so any changes made will be preserved for future versions. Thanks for your answer!
PeterK