c - 使用 '.' token 定义常量

标签 c constants

如果我这样定义常量,为什么会出现错误?

#‎define‬ F.NAME "First"
#define L.NAME "Second"
printf("%s %s\n", F.NAME, L.NAME);

但如果我这样做,一切都会很顺利

#define F_NAME "First"
#define L_NAME "Second"
printf("%s %s\n", F_NAME, L_NAME);

我得到的错误是。

Warning: missing white space after the macro name
Error: expected expressions before '.' token

为什么我不能用“.”定义常量?

最佳答案

因为规范不允许。不允许使用句点和大多数其他特殊字符(_ 除外)。

An identifier is a sequence of nondigit characters (including the underscore _, the lowercase and uppercase Latin letters, and other characters) and digits, which designates one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct. There is no specific limit on the maximum length of an identifier.

来自 C99 规范的 §6.4.2.1。

关于c - 使用 '.' token 定义常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21240565/

相关文章:

c - C 中的二进制搜索无法正常工作

php - 通过相应的值访问 PHP MySQLI 预定义常量?

javascript - 如何从 JavaScript 函数内部定义全局常量?

go - 使用结构对常量进行分组有哪些副作用

delphi - 如何在不更改库文件的情况下修改Delphi库文件中的常量?

c++ - 如果方法是const,如何找到 vector 的中值?

Arch Arm 的交叉编译不会生成功能可执行文件

c - 在 LINUX 上的 C 中打开 O_NONBLOCKING

c - 在 C 中分配数组和结构

c - 更多地了解 fseek() 和 EOF IN C