Pages

Wednesday, September 15, 2010

Invalid identifier character 0xfeff

I got this error while trying to compile a UTF-8 ecoded file with windows build go compiler. Error messages are as follows

UTF 8 =>
$ 8g hello.go 
hello.go:1: invalid identifier character 0xfeff 
hello.go:1: package statement must be first 
hello.go:1: non-declaration statement outside function body 
hello.go:1: syntax error: unexpected name, expecting semicolon or 
newline

Unicode (in notepad)=>
$ 8g hello.go 
hello.go:1: illegal NUL byte 
hello.go:1: illegal UTF-8 sequence 
        ff fe 70 00 
hello.go:1: invalid identifier character 0xfffd 
hello.go:1: illegal NUL byte 
hello.go:1: package statement must be first 
hello.go:1: illegal NUL byte 
hello.go:1: non-declaration statement outside function body 
hello.go:1: syntax error: unexpected name, expecting semicolon or 
newline 
hello.go:1: illegal NUL byte 
hello.go:1: too many errors 

Rob Pike suggest that my editor (Notepad ++) is misbehaving . I have tried Windows Notepad, X-ConTEXT, and notepad2 without any luck. Finally I got it working with EditPlus 3. The supported encoding is "UTF-8 without BOM" which is default for EditPlus 3 UTF, for Notepad ++ you have to select "UTF-8 without BOM" instead of only "UFT-8" and for Programmer's Notepad you have to select "UTF-8 No Mark". No such option in Windows Notepad, X-ConTEXT, or notepad2.

0 comments:

Post a Comment

 
Powered by NishantSoft