Issue
On somewhat of a lark, I wanted to use a µ
character in a function name in a C project. Is this just not possible? I get errors like
error: stray '\302' in program
I tried adding the options:
-fexec-charset=UTF-8
-finput-charset=UTF-8
to my build script, but I must not understand what those enable. I'm running this version of gcc:
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]
Solution
The C standard requires implementations to have the following characters in the source character set:
A-Z a-z 0-9 ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
as well as space, characters for horizontal tab, vertical tab, and form feed. It also requires some method of indicating the end of the line, although that is not necessarily an in-stream character (C 2011 [N1570] 5.2.1 3). Implementations may extend this character set, and they may permit other characters in identifiers, but such extensions are defined by each implementation, not the standard.
-finput-charset=…
does not specify what character set to use for the source character set. It specifies what the character set of the source input is, but that input is translated to GCC’s source character set.
Clang appears to accept µ as an identifier (tested on macOS and at Compiler Explorer), while GCC does not.
Answered By - Eric Postpischil Answer Checked By - Mary Flores (WPSolving Volunteer)