5

The project was doing fine, running fine, compiling fine. Until some seemingly random time it stopped being fine.

At the moment I'm getting around 200 stray errors:

./new:4: error: stray '\376' in program
./new:4: error: stray '\377' in program
./new:5: error: stray '\376' in program
./new:5: error: stray '\377' in program

From reading other posts it seems I have some bad characters in my code which I cannot see. So I emptied the whole file I was working on, but no luck. This error persists whatever I do.

Also, when compiling main.cpp (which it does first), it first and foremost includes #include <QApplication>, which is the start of the chain of "from 'file'" messages. This means it didn't really parsed much of main.cpp yet, but gets borked from reading internal Qt files.

I'm totally gazing in the dark here, what could this possible be, and how would I resolve this?

I'm using Qt 4.7.2, GCC 4.5.0 and Windows 7.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Taco de Wolff
  • 1,682
  • 3
  • 17
  • 34
  • 376 octal = 254 decimal and 0xFE hexadecimal. 377 octal = 255 decimal and 0xFF hexadecimal. If it was in the beginning of the file it would be the [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) for a UTF-16 encoded file ([UTF-16BE](https://en.wikipedia.org/wiki/Byte_order_mark#UTF-16)). – Peter Mortensen Jun 04 '23 at 18:42
  • It could be from including files at line 4, 5, etc. with BOMs (big endian, UTF-16BE) and encoded as UTF-16 file. – Peter Mortensen Jun 04 '23 at 18:44
  • Here is a similar one (it is severely underspecified, so it isn't clear if it is a UTF-18 little endian or big endian BOM): *[Stray /377 in Xcode](https://stackoverflow.com/questions/11025320/stray-377-in-xcode)* – Peter Mortensen Jun 04 '23 at 18:49

5 Answers5

4

Octal \376 \377 is 0xFEFF, which is the Unicode Byte-Order Mark. It is used to signal the endianness of a UTF-16 text file, and also to signal that a file is UTF-8-encoded. It should only occur at the start of a file, but it seems to have crept into the header comments in your library header file new, at lines 4 and 5. Locate this file, and delete those lines. (But only if they're comments!)

TonyK
  • 16,761
  • 4
  • 37
  • 72
2

Copy your code into Notepad and save it. Then remove your main.cpp and add the Notepad one to your project. Rebuild and check the result.

If it still persists then most probably the problem is not with your source, but with the Qt or gcc and/or gnulibc libraries. They probably got corrupted or are stored in a different, unsupported encoding.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shinnok
  • 6,279
  • 6
  • 31
  • 44
2

Your source file is probably encoded in UTF-16 or something like that.

Try copy-pasting the code in a new file and see if that helps.

the JinX
  • 1,950
  • 1
  • 18
  • 23
1

To me things like these happened in the past when I copied source from some web page.

Only typing it again solved the issue. But maybe some tool to convert the encoding might fix the issue as well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AndyAndroid
  • 4,039
  • 14
  • 44
  • 71
  • Retyping is ***not*** necessary. It is entirely possible to be rational in this matter (the stray errors of that type are usually UTF-8 byte sequences). The canonical question is: *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332/)* (but not for the error here; it is most likely for another reason, UTF-16 encoding of included files ([UTF-16BE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes) or [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes))). – Peter Mortensen Jun 04 '23 at 18:57
  • The most common ones can be detected by this regular expression: `\x{00A0}|\x{00A6}|\x{00AB}|\x{00AE}|\x{00BB}|\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 Jun 04 '23 at 19:00
  • Or in other words, while it is a very common error, this answer is not correct for this particular question. – Peter Mortensen Jun 04 '23 at 19:10
0

A conflict might exist. For example, I created a project named QTcpServer.pro, but when I tried to #include QTcpServer, I got many stray errors. Renaming my project (QTcpSvr.pro) solved this error.

Gardinal
  • 74
  • 6
  • What stray errors exactly? (They usually come in doublets or triplets, so sufficient many should be included.) There are many different reasons for stray errors. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/74774764/edit), not here in comments (*** *** *** *** *** ***[without](https://meta.stackexchange.com/a/131011)*** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 04 '23 at 19:14