Why does the following code make my machine do a beep-tone?
print '\78'
I have tested it in the interactive interpreter and running a script in the command-line. I have also tested it in an embedded environment and it does not invoke a beep there.
It interprets
\7as the octal escape, so it’s BEL with ASCII code 7. This is a character that, when printed on a terminal, rings a bell. Yes, a literal bell in ancient times with teletypes (and even some terminals). Since we pride ourselves in not letting 1960s technology go to waste every terminal emulator has the same capability of making a sound at the sight of a character. Why it doesn’t work in the embedded environment: Well, it’s probably no terminal emulator you’re having there.The documentation says that “As in Standard C, up to three octal digits are accepted.” Since
8is no valid octal digit it stops with\7.If you want the literal string
\78, prefix anr:If you want the character
0x78(x), then add anx:If you ask me, though, any octal niceties should be banned from programming languages unless when inventing new escape codes for them, e.g.
\o123for strings or0o153for literals. The two conventions carried over from C here into countless programming languages just because it takes no effort to do so is in my humble opinion misguided and stupid.