The value '\08'
is considered to be a multi-character constant, consisting of \0
(which evaluates to the number 0) and the ASCII character 8
(which evaluates to decimal 56). How it's interpreted is implementation defined. The C99 standard says:
An integer character constant has type int. The value of an integer
character constant containing a single character that maps to a
single-byte execution character is the numerical value of the
representation of the mapped character interpreted as an integer. The
value of an integer character constant containing more than one
character (e.g., 'ab'), or containing a character or escape sequence
that does not map to a single-byte execution character, is
implementation-defined. If an integer character constant contains a
single character or escape sequence, its value is the one that results
when an object with type char whose value is that of the single
character or escape sequence is converted to type int.
So if you would assign '\08'
to something bigger than a char
, like int
or long
, it would even be valid. But since you assign it to a char
you're "chopping off" some part. Which part is probably also implementation/machine dependent. In your case it happens to gives you value of the 8
(the ASCII character which evaluates to the number 56).
Both GCC and Clang do warn about this problem with "warning: multi-character character constant".