2

Instead of stray "\302" in a program which I found here, I got the error message:

algo.c:118: error: stray ‘\303’ in program
algo.c:118: error: stray ‘\215’ in program

I could not seem to figure it out. What is this?


For future reference, stray '\XXX' means an incomprehensible character to the compiler. The way to fix is to find the '\XXX' character (which now I find out is not always this Unicode. It can't be a wrong definition, such as '##' in '##define'), so delete or correct it. Good luck!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
donkey
  • 4,285
  • 7
  • 42
  • 68
  • Was this copied from Windows to Linux? What about the command `dos2unix`, have you tried that? – Engineer2021 Mar 13 '14 at 16:07
  • https://stackoverflow.com/a/6526863/2591612 – Engineer2021 Mar 13 '14 at 16:08
  • 1
    One reason could be that you have non-ASCII characters in your variable names. Visual Studio allows those, but not GCC. – Thomas Padron-McCarthy Mar 13 '14 at 16:08
  • If you are on Linux/Unix/Mac OSX, try typing "cat -vet algo.c" to see off characters. – Mark Setchell Mar 13 '14 at 16:09
  • 1
    You can look at line 118 in your file `algo.c` to find the problem. Maybe also post it to make your question understandable? – anatolyg Mar 13 '14 at 16:11
  • This is very odd, because when I was editing it in vim, every line of code looks just fine. But then I was trying to edit it in sublime text 2. All of the sudden there is an unknown latin character shown in the end of line 118. I think it was just hidden while in vim or something. But thank you very much! – donkey Mar 14 '14 at 11:25
  • Can you post the offending code, please? – Peter Mortensen Aug 20 '23 at 09:58
  • As [noted in comments](https://stackoverflow.com/questions/22384338/stray-303-and-stray-215-in-program-why?noredirect=1&lq=1#comment34071742_22389604), 303 215 (octal) → 0xC3 0x8D (hexadecimal) → UTF-8 sequence for Unicode code point U+00CD ([LATIN CAPITAL LETTER I WITH ACUTE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=200)). – Peter Mortensen Aug 20 '23 at 10:20
  • I can reproduce this problem with the Unicode character `Í` (UTF-8 encoded). With [GCC 7.5.0](https://gcc.gnu.org/gcc-7/) (Ubuntu 7.5.0-3ubuntu1~18.04), 2019-11-14 (yes, I know). – Peter Mortensen Aug 20 '23 at 10:24
  • UTF-8 sequences starting with 303 (octal) are not uncommon. Another one observed in the wild is 303 244 (octal) → 0xC3 0xA4 (hexadecimal) → UTF-8 sequence for Unicode code point U+00E4 ([LATIN SMALL LETTER A WITH DIAERESIS](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=224)). That is `ä`. I can't find the reference at this point, but I have [registered it](https://pmortensen.eu/world2/2023/05/01/unicode-blues-in-c-and-similar-languages-after-copying-from-web-pages-skype-chat-etc/). – Peter Mortensen Aug 20 '23 at 10:31
  • On some keyboard layouts, `Í` can be accidentally typed by hitting the key inbetween "+" and [backspace](https://en.wikipedia.org/wiki/Backspace). And then Shift + I. – Peter Mortensen Aug 20 '23 at 10:38
  • There isn't any need to search for it visually. It can be searched (and replaced) for by using the regular expression `\x{00CD}` in any modern text editor or IDE. Note: The notation is different in Visual Studio Code (and probably others): `\u00CD` (instead of `\x{00CD}`) – Peter Mortensen Aug 20 '23 at 10:44
  • A greater range of common stray characters, incl. some ***invisible*** (e.g. ZERO WIDTH SPACE) and ***visually identical*** (e.g., non-breaking space), can be searched for by regular expression `\x{00A0}|\x{00A6}|\x{00AB}|\x{00AE}|\x{00BB}|\x{00CD}|\x{00E4}|\x{2003}|\x{2009}|\x{200B}|\x{200C}|\x{2013}|\x{2014}|\x{2018}|\x{2019}|\x{201C}|\x{201D}|\x{2028}|\x{2029}|\x{202A}|\x{202B}|\x{202C}|\x{2060}|\x{21B5}|\x{2212}|\x{2217}|\x{2260}|\x{FEFF}|\x{FF1A}|\x{FFFC}|\x{FFFD}` – Peter Mortensen Aug 20 '23 at 10:50
  • The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332/)* – Peter Mortensen Aug 20 '23 at 10:54
  • OK, the OP has left the building: *"Last seen more than 5 years ago"* – Peter Mortensen Aug 20 '23 at 11:16

3 Answers3

6

These are:

00C3    LATIN CAPITAL LETTER A WITH TILDE
        : 0041 0303
        U+00C3, character Ã‬, decimal 195, hex 0xC3, octal \303, binary 11000011
        UTF-8: 0xc3 0x83

008D    <control>
        = REVERSE LINE FEED
        U+008D, character ‬, decimal 141, hex 0x8D, octal \215, binary 10001101
        UTF-8: 0xc2 0x8d

I'm guessing those aren't there deliberately. Sometimes editing in a terminal can produce this if you start typing before the window has fully loaded and done its stty thing. I often see this sort of thing in emacs.

Solution: go to the appropriate lines and remove the characters. cat -te or less are useful for identifying which characters are problematic.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
abligh
  • 24,573
  • 4
  • 47
  • 84
  • Easiest is normally to edit the file, retype the offending line exactly as shown below it, and deleting the original with (invisible) garbage in it. – vonbrand Mar 13 '14 at 20:02
  • It was a character that was not shown in vim but appeared in sublime text 2. I think I might have mistakenly typed this in and forgot it because the length of the code. – donkey Mar 14 '14 at 11:26
  • But my fix was simply to delete the latin capital letter. I did not see reverse line feed char tho. Is that because it just automatically come with a latin character? – donkey Mar 14 '14 at 11:32
  • 4
    In UTF-8 the sequence 0xC3 0x8D represents the single character [U+00CD LATIN CAPITAL LETTER I WITH ACUTE](http://codepoints.net/U+00CD) which is probably what you saw. –  Mar 14 '14 at 15:22
0

As an additional answer, it happens to me a lot when I want to type characters that requires an AltGr key combination. Usually my fingers slipped and it results in hidden garbage character.

As said, a better solution is to rewrite the spotted line.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
n0p
  • 3,399
  • 2
  • 29
  • 50
0

Using non-ASCII characters in code may cause these errors.

I had the same issue using öäü... in an enum.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Haselnussstrauch
  • 333
  • 2
  • 10
  • Re *"in an enum"*: But those ***are*** [allowed by the standard](https://stackoverflow.com/questions/12692067/and-other-unicode-characters-in-identifiers-not-allowed-by-g), but [GCC did not catch up before version 10](https://stackoverflow.com/questions/12692067/and-other-unicode-characters-in-identifiers-not-allowed-by-g/42158646#42158646) (May 2020). – Peter Mortensen May 03 '23 at 19:22
  • Yes, the UTF-8 sequence for [ä](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=224) also starts with 303 (octal. hexadecimal C3), like in this question. – Peter Mortensen Aug 20 '23 at 11:13