在c++中,宏/定义区分大小写
Are macros/definitions case sensitive in C++?
假设您有一个名为Add.h的头文件。如果有
,程序会链接吗?#ifndef ADD_H
#define Add_H
作为你的include守卫?
编辑:头文件
#include <iostream>
using namespace std;
#ifndef _RATIONAL_H
#define _Rational_H
class Rational
{
long long _p;
long long _q;
void simp();
public:
Rational();
Rational( long long P, long long Q = 1);
Rational( const Rational& );
};
#endif
是的,宏在c++中是区分大小写的。假设大多数编程语言中的所有内容都是区分大小写的,这可能是一条很好的经验法则。在只有少数几种语言中,您可以访问,例如,foo
和Foo
作为相同的变量(我认为Visual Basic -不确定有多少其他语言)。
如果你对这么简单的东西不确定,最简单的方法就是用你自己的编译器试试:)
编辑:要知道它是否确实实际上工作,并且链接器不只是忽略它,因为它不一定需要定义(可能取决于ifdef/环境)尝试以下代码:#include <iostream>
#define TEST
bool success = false;
#ifdef Test
bool success = true;
#endif
void main() {
std::cout << success << std::endl;
system("pause"); //Wait to press enter before closing
}
如果控制台显示数字1 (std::cout将true
转换为1,将false
转换为0,除非您告诉它否则),那么宏确实是大小写敏感的
更新:我刚刚尝试在Visual Studio 2015中编译上述代码,它确实给出了0
的输出。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 部分定义/别名模板模板参数
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- #为""定义宏;静态";针对不同的上下文
- 如何确保C++函数在定义之前声明(如override关键字)
- C++函数中未定义的开关大小写
- HRESULT:将自定义代码与系统一个区分开
- 递归中的锚点大小写定义
- 当C/C++程序切换语句转到未定义的大小写并且缺少默认值时,它的正确行为是什么:
- 使用结构中定义的枚举作为C++中的大小写常量
- 隐式声明和隐式定义的复制构造函数之间的区别是什么
- VS2010上不区分大小写的字符串比较-为每个版本的VS播放#if定义的语句
- 在c++中,宏/定义区分大小写
- 定义和实例化的区别是什么?
- 在滚动区使用自定义Qt类,并强制不调整元素的大小,但滚动条出现
- c++ #定义和连接大小写(我使用gcc)
- 为不区分大小写的映射定义模板
- 如何区分子模板类的定义和声明