CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2006
    Posts
    384

    Compilation error with backslash

    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.

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Compilation error with backslash

    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
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  3. #3
    Join Date
    Jan 2006
    Posts
    384

    Re: Compilation error with backslash

    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.

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Compilation error with backslash

    Quote Originally Posted by humble_learner
    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/
    Please don't forget to rate users who helped you!

  5. #5
    Join Date
    Jan 2006
    Posts
    384

    Re: Compilation error with backslash

    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 ?

  6. #6
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Compilation error with backslash

    Quote Originally Posted by humble_learner
    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)
    Please don't forget to rate users who helped you!

  7. #7
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Compilation error with backslash

    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')
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  8. #8
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Compilation error with backslash

    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.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured