Results 1 to 7 of 7

Thread: What is \xb8\x00\x00\x00.... in C language

  1. #1
    Join Date
    Aug 2010
    Location
    INDIA
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    What is \xb8\x00\x00\x00.... in C language

    Hi friends,

    I was reading an article and I found this line of code for a C program.

    Code:
    static char abc[7]="\xb8\x00\x00\x00"
                               "\xff\xe0"
    What is meaning of the code in double quotes?

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: What is \xb8\x00\x00\x00.... in C language

    It's a series of hexadecimal escape sequences. Each '\xNN' represents the character with value NN in hexadecimal.

  3. #3
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: What is \xb8\x00\x00\x00.... in C language

    Whoever wrote this code has no idea what they are doing. There is no guarantee that 0xb8, 0xff and 0xe0 will fit in a char.
    「明後日の夕方には帰ってるからね。」


  4. #4
    Join Date
    Feb 2011
    Location
    Great White North
    Beans
    128
    Distro
    Kubuntu 11.10 Oneiric Ocelot

    Re: What is \xb8\x00\x00\x00.... in C language

    Quote Originally Posted by Bachstelze View Post
    Whoever wrote this code has no idea what they are doing. There is no guarantee that 0xb8, 0xff and 0xe0 will fit in a char.
    If it is declared unsigned, shouldn't it work. Also does C declare a char as signed when there is no unsigned or signed prefix in the declaration.
    VHDL and C FTW

    Designing a custom CPU based on MIPS

  5. #5
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: What is \xb8\x00\x00\x00.... in C language

    Quote Originally Posted by alegomaster View Post
    If it is declared unsigned, shouldn't it work. Also does C declare a char as signed when there is no unsigned or signed prefix in the declaration.
    It is implementation-defined whether char actually means signed char or unsigned char.

    EDIT: It will work if it is declared unsigned, yes. Here it is not.
    Last edited by Bachstelze; February 28th, 2012 at 11:36 PM.
    「明後日の夕方には帰ってるからね。」


  6. #6
    Join Date
    Jun 2011
    Location
    United Kingdom
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: What is \xb8\x00\x00\x00.... in C language

    Quote Originally Posted by Bachstelze View Post
    It is implementation-defined whether char actually means signed char or unsigned char.
    Would I be right in thinking that passing compiler options would set the default char signed-ness? So...the article could suggest passing the -funsigned-char argument to gcc...but maybe I'm wrong.

  7. #7
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: What is \xb8\x00\x00\x00.... in C language

    Quote Originally Posted by MG&TL View Post
    Would I be right in thinking that passing compiler options would set the default char signed-ness? So...the article could suggest passing the -funsigned-char argument to gcc...but maybe I'm wrong.
    Yes, you're right. So... maybe, but I think that's quite unlikely.
    「明後日の夕方には帰ってるからね。」


Bookmarks

Posting Permissions

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