<p>I assume that C didn't originate the idea that, for example, the sequence <code>\t</code> inside a string literal should mean a tab character, that <code>\&quot;</code> should allow embedding a quote so that it isn't seen as the end of the string, etc.</p>
<p>But where <em>did</em> this idea come from? Did B, or BCPL come up with it? Or perhaps something older? Or was it even inspired by something that existed before what we'd call a &quot;programming language&quot; today?</p>
<p>And did languages before C happen to use the same set of escape sequences?</p>

<syntax><strings><history>
What was the first language to use backslashes as escape characters in string literals?
CC BY-SA 4.0
2024-05-17T04:57:33.497Z
Doesn't this belong on https://retrocomputing.stackexchange.com/?
Adám
CC BY-SA 4.0
2024-05-17T05:07:17.480Z
I think it's in line with other questions here in the tag, and the retrocomputing folks don't seem to talk about languages that are any more esoteric than Fortran, so I thought I'd get a better answer here. But if people think it should be moved, I won't object.
Karl Knechtel
CC BY-SA 4.0
2024-05-17T05:14:01.707Z
I think this question is a good fit for this site - it also leaves room open to answer 'why' it's used (which seems like something the question's asking).
Redz
CC BY-SA 4.0
2024-05-17T06:21:15.140Z
@Redz I wasn't explicitly asking that, but it seems like something that answers might include in order to understand the historical context, and I would certainly support that.
Karl Knechtel
CC BY-SA 4.0
2024-05-17T07:10:43.020Z
[Duplicate?](https://stackoverflow.com/q/1675643/5306507)
Adám
CC BY-SA 4.0
2024-05-17T09:04:08.677Z
There are really two different things that backslash escapes area currently used for: firstly, as what some languages refer to as a "release character", to make the next character literal when it would *normally* have special meaning; and secondly, as part of a *digraph*, to represent some character that would otherwise be hard to include. It's possible the two have different histories. It's also unclear if you're interested in the *idea* of such sequences, or *the specific use of backslash* for them.
IMSoP
CC BY-SA 4.0
2024-05-17T17:43:23.877Z
According to @Adám's link, it originated in C. B had something similar, but it used asterisk instead of backslash.
Barmar
CC BY-SA 4.0
2024-05-18T02:36:54.867Z
Retrocomputing.SE would love this question. See for example https://retrocomputing.stackexchange.com/questions/20241/ and https://retrocomputing.stackexchange.com/questions/20273/
texdr.aft
CC BY-SA 4.0
2024-05-18T02:53:38.927Z
@texdr.aft I think I'll rephrase it and ask there, yeah.
Karl Knechtel
CC BY-SA 4.0
2024-05-18T02:58:44.987Z
@IMSoP By "digraph" do you also mean sequences using more than two characters, like `\377`, or (in modern versions) `\U000000ff`? I think that "escape sequence" is sometimes understood to mean only what you call "release character", but in common parlance (especially in the context of string literals) it typically means both kinds of sequences. By "escape character" I mean the common prefix for either kind of sequence in the current scheme. There needs to be a way to represent that prefix literally, which is why the two categories are conflated - after all, which does ``\\`` belong to?
Karl Knechtel
CC BY-SA 4.0
2024-05-24T12:04:56.830Z
Cross-posting to two different sites is strongly discouraged on Stack Exchange. It should only be posted here if it's deleted here (by you or by the moderators).
Criticize SE actions means ban
# What was the first language to use backslashes as escape characters in string literals?
Posted by: username_0 on 2024-05-17
I assume that C didn't originate the idea that, for example, the sequence `\t` inside a string literal should mean a tab character, that `\"` should allow embedding a quote so that it isn't seen as the end of the string, etc.

But where *did* this idea come from? Did B, or BCPL come up with it? Or perhaps something older? Or was it even inspired by something that existed before what we'd call a "programming language" today?

And did languages before C happen to use the same set of escape sequences?
**Tags:** syntax strings history
> **Comments:**
> **username_1**: Doesn't this belong on https://retrocomputing.stackexchange.com/?  
> **username_0**: I think it's in line with other questions here in the tag, and the retrocomputing folks don't seem to talk about languages that are any more esoteric than Fortran, so I thought I'd get a better answer here. But if people think it should be moved, I won't object.  
> **username_2**: I think this question is a good fit for this site - it also leaves room open to answer 'why' it's used (which seems like something the question's asking).  
> **username_0**: @Redz I wasn't explicitly asking that, but it seems like something that answers might include in order to understand the historical context, and I would certainly support that.  
> **username_1**: [Duplicate?](https://stackoverflow.com/q/1675643/5306507)  
> **username_3**: There are really two different things that backslash escapes area currently used for: firstly, as what some languages refer to as a "release character", to make the next character literal when it would *normally* have special meaning; and secondly, as part of a *digraph*, to represent some character that would otherwise be hard to include. It's possible the two have different histories. It's also unclear if you're interested in the *idea* of such sequences, or *the specific use of backslash* for them.  
> **username_4**: According to @Adám's link, it originated in C. B had something similar, but it used asterisk instead of backslash.  
> **username_5**: Retrocomputing.SE would love this question. See for example https://retrocomputing.stackexchange.com/questions/20241/ and https://retrocomputing.stackexchange.com/questions/20273/  
> **username_0**: @texdr.aft I think I'll rephrase it and ask there, yeah.  
> **username_0**: @IMSoP By "digraph" do you also mean sequences using more than two characters, like `\377`, or (in modern versions) `\U000000ff`? I think that "escape sequence" is sometimes understood to mean only what you call "release character", but in common parlance (especially in the context of string literals) it typically means both kinds of sequences. By "escape character" I mean the common prefix for either kind of sequence in the current scheme. There needs to be a way to represent that prefix literally, which is why the two categories are conflated - after all, which does ``\\`` belong to?  
> **username_6**: Cross-posting to two different sites is strongly discouraged on Stack Exchange. It should only be posted here if it's deleted here (by you or by the moderators).  
---
## 0 answers
