Compiler error about stray characters

I had made a program using Visual Micro and here my sketch compiled without error. But in Arduino IDE 2.0 I get a lot of compiler error about stray characters. First I might point out that I have read previous threads about that and they did not help me. I upload my code.
The first lines of output reads
C:\Users\Jan Work\OneDrive\Dokument\Arduino\MegaDisplayStation\DataReader.ino:1:1: error: stray '\357' in program
#include "UserFunctions.h"
^
It seem to point at the # token ?! It's a valid character and there are no token before it. I surely can't see where any stray characters could be. Why not implementing an editor feature that can display them ? Btw what is \357 ?

DataReader.ino (1.3 KB)
MegaDisplayStation.ino (10.0 KB)
RtcClock.ino (3.4 KB)
TFTDisplay.ino (11.4 KB)
UserFunctions.h (1.6 KB)

DataReader.ino starts with a couple of invisible characters:

$ xxd DataReader.ino
00000000: efbb bf23 696e 636c 7564 6520 2255 7365  ...#include "Use
00000010: 7246 756e 6374 696f 6e73 2e68 220d 0a0d  rFunctions.h"...
...

It's a UTF-8 BOM: Byte order mark - Wikipedia

You can open it in an IDE or editor like VS Code and save it with a different encoding (e.g. UTF-8 without BOM): https://code.visualstudio.com/docs/editor/codebasics#_file-encoding-support

Edit: In the Arduino IDE 2.0, you can use Ctrl+Shift+P Editor: Change File Encoding Save with Encoding UTF-8.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.