Porting code which requires default char to be unsigned to a code-base which does not have this requirement
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 thi开发者_如何学运维s project to our code-base without breaking anything" but that would be asking for a solution and i would not learn anything ;)
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.
精彩评论