Ho trovato un codice confuso durante la revisione del codice e sono un po 'perplesso. Facendo qualche ricerca ho trovato questa situazione. Ho scritto questo esempio di codice per evidenziare il problemaQuesto carattere dovrebbe essere non firmato?
char d = '©';// this is -87,the copyright symbol , (actually its 169 unsigned)
if(ispunct(d)) // will assert.
{
}
modo, il programmatore che era bug fixing, fatto quanto segue:
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.
{
}
La mia domanda è se è OK per fare il unsigned char
? Idealmente, non utilizzerei lo char
ma uso un char Unicode per evitare questo tipo di problema, ma il software è molto vecchio e non verrà reingegnerizzato in tempi brevi.
Sto utilizzando Visual Studio 2008. ispunct()
può essere trovato in ctype.h
.
Lo stesso vale per il resto delle funzioni della stessa famiglia, ad esempio 'isalpha()', 'toupper()' e così via. – caf