我有一个名为 setlocal 的变量和一个名为 void SetLocal(void) 的函数
我正在使用 C51 keil 编译器构建代码,链接器给出以下错误:
“外部属性与公共(public)属性不匹配”
函数和变量不能使用相同的名称吗?用不同的大小写?
最佳答案
那个特定的编译器是为嵌入式系统(使用 8051 芯片)设计的,并且真正针对那些环境。我见过那个领域的编译器甚至不支持 float ,Keil 明确表示,虽然它基于 C90,但有deviations从那个标准。
根据 Keil website 中列出的编译器限制:
Names may be up to 255 characters long. The C language provides for case sensitivity in regard to function and variable names. However, for compatibility reasons, all names in the object file appear in capital letters. It is therefore irrelevant if an external object name within the source program is written in capital or small letters.
因此可以肯定的是,就链接器而言,setlocal
变量和 SetLocal
函数之间存在冲突,两者都是被视为 SETLOCAL
。
这也解释了(如您的评论中所述)为什么将变量名称更改为 setlocal1
可以解决您的问题。虽然这些符号不区分大小写,但它们在 255 个字符内是唯一的。
关于c - 相同的名称,但在 c 中具有不同的 case 变量和函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066925/