The value '\08' is considered a multi-character constant consisting of \0 (which evaluates to the number 0) and the ASCII 8 character (which evaluates to decimal 56). How this is interpreted is determined by the implementation. The C99 standard says:
An integer character constant is of type int. The value of an integer character constant containing one character that maps to a single-byte execution character is a numeric value representing the character being displayed, interpreted as an integer. The value of an integer character constant containing more than one character (for example, "ab") or containing a character or escape sequence that does not match a single-byte execution character is from the implementation . If an integer character constant contains a single character or an escape sequence, its value is the result when an object of type char whose value is a single character or the escape sequence is converted to int.
So, if you assigned '\08' to something bigger than char , like int or long , it would be valid. But since you assign it to char , you "chop off" some part. Which part is probably also implementation / machine dependent. In your case, this gives you a value of 8 (an ASCII character that evaluates to 56).
Both GCC and Clang warn of this problem with a "warning: multi-character character constant."
Darkdust
source share