PDA

View Full Version : What is \xb8\x00\x00\x00.... in C language



c2tarun
February 28th, 2012, 04:51 PM
Hi friends,

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



static char abc[7]="\xb8\x00\x00\x00"
"\xff\xe0"


What is meaning of the code in double quotes?

r-senior
February 28th, 2012, 05:02 PM
It's a series of hexadecimal escape sequences. Each '\xNN' represents the character with value NN in hexadecimal.

Bachstelze
February 28th, 2012, 10:07 PM
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.

alegomaster
February 28th, 2012, 11:22 PM
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.

Bachstelze
February 28th, 2012, 11:30 PM
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.

MG&TL
February 28th, 2012, 11:37 PM
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.

Bachstelze
February 28th, 2012, 11:46 PM
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.