4

I am working on a simple project in Objective-C in Xcode and I'm getting some stray/ errors about the following line of code:

if(celsius < −273.15) {
        NSLog(@"It is impossible to convert temperatures less than −273.15 degrees Celsius, because this is absolute zero, the coldest possible temperature.");
    }

It's actually only about the first line, but I wanted to give some context.

Any suggestions?

I've looked it up here on SO, but everyone else's error hasn't had such simple code like mine, although it appears they have a common problem of having the wrong encoding for certain punctuation, perhaps?

It's got to be just some syntax this on my if statement..

UPDATE:

It looks as though it also displays 2 other stray errors:

Stray '\210' Stray '\222'

Qcom
  • 17,193
  • 29
  • 84
  • 112
  • The real reason is probably copying code from a web page, PDF document, or through chat, like Skype Chat (or other formatted text). – Peter Mortensen Mar 05 '21 at 06:10
  • The canonical is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Mar 05 '21 at 06:11
  • The 3 stray errors is one unit and are octal numbers: 342 210 222 (octal) → 0xE2 0x88 0x92 (hexadecimal) → UTF-8 sequence for Unicode code point U+2212 ([MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). – Peter Mortensen Mar 06 '21 at 20:09
  • A question with this specific error is *[Error with stray ‘\342’ stray ‘\210’ stray ‘\222’ in C program in Linux system call](https://stackoverflow.com/questions/38343182)*. – Peter Mortensen Mar 06 '21 at 20:09

2 Answers2

6

− != -

Your minus, isn't a minus.

Joshua Weinberg
  • 28,440
  • 2
  • 96
  • 90
  • Oh wow, thanks, sorry for wasting your time, what did the compiler recognize mine as? – Qcom Aug 09 '10 at 18:17
  • 1
    Looks like yours is a 'minus sign' whereas the compiler expects a 'hyphen-minus'. – Joshua Weinberg Aug 09 '10 at 18:20
  • Cool, thanks, when I use this code however: if(celsius < -!=-273.15), I get the following error, except only 1 this time, no stray: error: expected expression before '!=' token – Qcom Aug 09 '10 at 18:22
  • if(celsius < -!=-273.15) that expression makes no sense. You mean if(celsius < -273.15)? – Joshua Weinberg Aug 09 '10 at 18:24
  • Copy this directly.. if (celsius < -273.15) And fix the encoding on your file – Joshua Weinberg Aug 09 '10 at 18:26
  • Wait, sorry, I see what you mean the first time, my bad, I just copied and pasted your last comment and it worked perfectly.. – Qcom Aug 09 '10 at 18:26
  • Glad its fixed, I'm not sure how you're accidentally using those characters though. Is your language set to something other than english? – Joshua Weinberg Aug 09 '10 at 18:27
  • Hmm, good point, no, I'm using Xcode 3.2.3 on Snow Leopard with English language.. – Qcom Aug 09 '10 at 18:31
  • Nope, actually, all I did was press the standard dash / minus key on my macbook's keyboard, the one right next to 0. – Qcom Aug 09 '10 at 18:38
  • I had this issue as well. Copy and pasting the function protocols from the documentation fixed the issue. – cynistersix May 11 '12 at 23:42
  • To be more precise, it is Unicode code point U+2212 ([MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). In most text editors it can be searched/replaced by a regular expression search for `\x{2212}`. – Peter Mortensen Mar 06 '21 at 20:13
1

Make sure that your " characters are straight up and down (and not of the left/right slanted variety).

codemonkey
  • 2,667
  • 1
  • 24
  • 34