cgmb / guardonce

Utilities for converting from C/C++ include guards to #pragma once and back again.
MIT License
142 stars 3 forks source link

First line of file is ignored if encoded as UTF-8 with BOM #23

Closed cgmb closed 6 years ago

cgmb commented 6 years ago

When looking for preprocessor directives, guardonce looks for # characters that have only been preceded by whitespace. For files that are UTF-8 with BOM, the BOM is interpreted as a series of characters that precede everything else on the line. As such, no preprocessor commands can be found on the first line of the file.

So, this is only a problem if the guard is on the first line of the file. If it appears anywhere else, the guard is found as normal and the BOM passes through guardonce unmodified to appear in the output as expected.

Experimenting with GCC, it seems that the BOM is ignored by compilers. This is probably reasonable behaviour, as it's very unlikely that a C header file could start with those characters and still be valid.