Thursday 6 March 2014

error: stray ‘\302’ in program


Make and meet this error!

$ gcc -g -Wall -o test callback_simple.c
callback_simple.c:7:1: error: stray ‘\302’ in program
callback_simple.c:7:1: error: stray ‘\240’ in program
callback_simple.c:9:1: error: stray ‘\302’ in program
callback_simple.c:9:1: error: stray ‘\240’ in program
callback_simple.c: In function ‘sig_handler’:
callback_simple.c:13:5: error: stray ‘\302’ in program
callback_simple.c:13:5: error: stray ‘\240’ in program

\302 is the octal representation of the UTF-8 sequence 0xC2

You have invalid chars in the source. If you don't have any valid non ascii chars in your source, maybe in a double quoted string literal, you can simply convert your file back to ascii with the following command:
tr -cd '\11\12\15\40-\176' < old.c > new.c
It works!