I found some confusing code during code review and am a bit puzzled. Doing some research I found this situation. I wrote this sample of code to highlight the problem
char d = '©';// this is -87,the copyright symbol , (actually its 169 unsigned)
if(ispunct(d)) // will assert.
{
}
so, the programmer who was bug fixing, did the following:
char d = '©';// this is -87,the copyright symbol , (actually its 169 unsigned)
if(ispunct((unsigned char)d)) // will not assert, because it will be 169.
{
}
My question is whether it is OK to make the char
unsigned ? Ideally, I wouldn't use char
but use a Unicode char to avoid this kinds of problem, but the software is very old and wont be reengineered any time soon.
I am using Visual Studio 2008. ispunct()
can be found in ctype.h
.