0

I'm trying to code in C with the bit operator 'or' (¦) (quite simple, I know).

However, when I compile it in GCC, I get:

error: stray \302 and stray \246

I tried to look for a solution to this problem, and all that I saw was that this error happens when the compiler doesn't recognize the symbol. What can I do to make it work?

My code is:

#include "stdio.h"

int main(int argc, char const *argv[]) {
  int x, y , z;
  x = 0xffff;
  y = 0x8888;
  z = x ¦ y;
  printf("0x%u \n", z);
  return 0;
}

Here is the error on the terminal:

ex_8_4.c: In function ‘main’:
ex_8_4.c:19:3: error: stray ‘\302’ in program
   z = x ¦ y;
   ^
ex_8_4.c:19:3: error: stray ‘\246’ in program
ex_8_4.c:19:12: error: expected ‘;’ before ‘y’
   z = x ¦ y;
            ^

Apparently I used the wrong symbol (¦ instead of |) (for some reason that's how it's appear in the book), so now it's working.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sami
  • 13
  • 3
  • 2
    it's not the same char as `|`. Re-type it. – Jean-François Fabre May 03 '17 at 18:42
  • 1
    You should use the pipe `|` character. – RoiHatam May 03 '17 at 18:44
  • 2
    Please cut and paste any error messages directly into your question, rather than link images of your terminal. – John Bode May 03 '17 at 18:59
  • 2
    There is no such operator in the C language. – too honest for this site May 03 '17 at 19:26
  • There isn't any need to retype anything. A direct analysis is: 302 246 (octal) → 0xC2 0xA6 (hexadecimal) → UTF-8 sequence for Unicode code point U+00A6 ([BROKEN BAR](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128)). It can be searched for (and replaced) using regular expression `\x{00A6}` in any modern text editor or IDE (note: The notation is different in Visual Studio Code (and probably others): `\u00A6` (instead of `\x{00A6}`)). – Peter Mortensen May 01 '23 at 03:27
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen May 01 '23 at 03:27
  • Correction (URL): [BROKEN BAR](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=128) – Peter Mortensen May 01 '23 at 03:43

3 Answers3

3

The character ¦ is not correct bitwise or operator. Search for this | in your keyboard. This code compiles well in my machine with |.

#include "stdio.h"
int main(int argc, char const *argv[]) {
    int x, y , z;
    x = 0xffff;
    y = 0x8888;
    z = x | y;
    printf("0x%u \n",z );
    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
ShivaGaire
  • 2,283
  • 1
  • 20
  • 31
1

You are using the wrong character. You should use: |

So, your code should look like this:

#include "stdio.h" 

int main(int argc, char const *argv[])
{ 
     int x, y, z; 
     x = 0xffff; 
     y = 0x8888; 
     z = x | y; 
     printf("0x%u \n", z); 
     return 0; 
}
1

If you can't find the proper character (| vs ¦), use the trigraph ??!.

Your line would look like this

z = x ??! y;
pmg
  • 106,608
  • 13
  • 126
  • 198
  • 1
    Trigraphs are a desperation measure, not least because you have to explicitly enable them with GCC using `-trigraphs` (and you might need `-Wno-trigraphs` too). – Jonathan Leffler May 03 '17 at 19:21
  • @JonathanLeffler: my GCC (version 4.9.2) compiles cleanly with `-std=c89 -pedantic`. – pmg May 03 '17 at 19:51
  • If you add `-Wall`, I believe you'll get a warning. Using GCC 7.1.0: `gcc -std=c11 -pedantic -Wall -Werror -c cox.c` yields: `cox.c:3:1: error: trigraph ??= converted to # [-Werror=trigraphs]` and `??=include ` identifying the line with the trigraph. So do versions 5.2.0 and 6.1.0. Without the `-Wall`, they aren't worried about the trigraphs. (I don't happen to have a GCC 4.x on this machine.) I don't compile without `-Wall` (or `-Werror` or `-Wextra`). – Jonathan Leffler May 03 '17 at 20:01