I am working on code that takes as input a ton of ascii text defined by specific protocol. The original author interpreted “string(1)” datatypes in the original protocol as chars in the code.
There have been a lot subtle bugs in corner cases where you have code such as:
char theChar = whatever();
if(theChar == 7) {...}
where was was really meant was:
if(theChar == '7') {...}
In order to attempt to catch all of these at once, is there a way to disable the implicit casting to ‘char’? If not, what is the best way to go about tracking all of these down?
You should be able to write a trivial replacement class for char (which holds a char as its data, and provides a few cast operators to allow it to be used as if it were a char) that doesn’t allow implicit casts to/from ints, and then do a search and replace of ‘char’ with the ‘mychar’. This will throw up compiler errors that you can fix, and then if you wish you can revert the code to using char again, or stick with your class.
This is a good example of a place where temporary use of macros is so useful in c++…