Click to See Complete Forum and Search --> : Compilation error with backslash


humble_learner
March 1st, 2006, 06:36 AM
Hi,

While compiling my file in VC++, I get the errors listed below with reference to the following line of code -

wsprintf( szDesc,L"DSN=%s\xFF Database=MyDataBase Server\xFF Description=MyDataBase MyData MySource\xFF Server=%s\xFF Trusted_Connection=yes\xFF \xFF ",szDSNName,strServer);

Error -
error C2002: invalid wide-character constant

My project settings have UNICODE for pre-processor directives. My user locale and default locale are both Japanese while my OS is English.
The backslash character appears as a yen symbol in my file.

The same file compiles without issues on another machine in our group.

Can someone please explain what could be the reason ?

Thanks.

SuperKoko
March 1st, 2006, 06:44 AM
I think that the problem is the \xFF which does not map to an unicode character but an extended ASCII character.
You should probably use \xFFFF or \x00FF

humble_learner
March 1st, 2006, 06:53 AM
Thanks for the advice.
Can you please guess what the author of the code (it is a code which I am trying to maintain) is trying to do by using \xFF ?
Is he trying to use "xFF" as a string or something ? Have not been able to figure out.

philkr
March 1st, 2006, 07:01 AM
Thanks for the advice.
Can you please guess what the author of the code (it is a code which I am trying to maintain) is trying to do by using \xFF ?
Is he trying to use "xFF" as a string or something ? Have not been able to figure out.
\xFF is replaced by the ASCII character with value FF (=255). This is probably used as a kind of delimiter.
You can find the ASCII codes here: http://www.lookuptables.com/

humble_learner
March 1st, 2006, 07:08 AM
I checked up the look up table and the Extended ASCII codes seem to indicate that 255 is space (as per the link you have give me). Why has the author taken the trouble to indicate space as \xFF when he could simple have included a space character directly ?

philkr
March 1st, 2006, 07:29 AM
I checked up the look up table and the Extended ASCII codes seem to indicate that 255 is space (as per the link you have give me). Why has the author taken the trouble to indicate space as \xFF when he could simple have included a space character directly ?
That is not correct. The symbol 255 is a white square. Unfortunately the background color of the web site is also white, so it looks empty.
BTW: Space has number 32 (0x20)

Graham
March 1st, 2006, 09:29 AM
try \x00ff. No guarantees, but the compiler might interpret four digits as a wide character.

Note that there is a potential "gotcha" using hex escape sequences - the standard says that there is no limit on the number of hex digits, so strings like "followed by\x0Da new line" will not do what you might expect. (It will try to put in the character '\x0da', not '\x0d', 'a')

SuperKoko
March 1st, 2006, 11:00 AM
character 255 in the extended ASCII table is the "espace inséquable" (I don't know the english name).
Two words delimited by an "espace inséquable" cannot appear on a different line.