问题描述
有点费劲,我想在C项目的函数名称中使用µ
字符.这是不可能的吗?我收到类似
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
我尝试添加选项:
-fexec-charset=UTF-8
-finput-charset=UTF-8
我的构建脚本,但是我一定不明白那些启用了什么.我正在运行此版本的gcc:
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]
推荐答案
C标准要求实现在源字符集中具有以下字符:
The C standard requires implementations to have the following characters in the source character set:
A-Z a-z 0-9 ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
以及空格,水平制表符,垂直制表符和换页符的字符.它也需要某种指示行尾的方法,尽管这不一定是插播字符(C 2011 [N1570] 5.2.1 3).实现可能会扩展此字符集,并且可能允许标识符中包含其他字符,但是此类扩展是由每个实现(而不是标准)定义的.
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=…
没有指定用于源字符集的字符集. 它指定源输入的字符集是什么,但该输入会转换为GCC的源字符集.
-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似乎接受µ作为标识符(已在macOS和 Compiler Explorer 上进行了测试),而GCC则不接受.
Clang appears to accept µ as an identifier (tested on macOS and at Compiler Explorer), while GCC does not.
这篇关于是否可以在C源代码中使用特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!