Visual Studio C ++预处理器行为已更改?

时间:2016-05-17 06:12:50

标签: visual-studio visual-studio-2010 visual-studio-2015 c-preprocessor

我使用Visual Studio C ++预处理器预处理某些文件,这些文件不是 C或C ++文件(我觉得非常方便)。

最近我从Visual Studio 2010升级到2015,发现预处理器行为略有改变。一些适用于VS2010的文本在VS2015上出错,反之亦然。

为了说明不同之处,这里有两个衬管文件ok2010.cok2015.c,以及运行VS2010和VS2015的预处理命令行:

ok2010.c:

#define X `0'`'

ok2015.c:

#define X `0'`'`'

VS2010上的预处理:

c:\>cl -E ok2010.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ok2010.c
#line 1 "ok2010.c"

c:\>cl -E ok2015.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ok2015.c
#line 1 "ok2015.c"
ok2015.c(1) : error C2001: newline in constant

VS2015上的预处理:

c:\>cl -E ok2010.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ok2010.c
#line 1 "ok2010.c"
ok2010.c(1): error C2001: newline in constant

c:\>cl -E ok2015.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

ok2015.c
#line 1 "ok2015.c"

我猜这个预处理器处理不同的 tick ')和反引号`),并期望它们是平衡的。当它们不平衡时,它会在引用的常量表达式中报告换行符 VS2010完全忽略了反引号并且只希望得到平衡,所以这种行为是有道理的 但是,我无法理解VS2015的行为,因为只有当刻度线和反引号都平衡时它才有效...

有什么想法吗?

0 个答案:

没有答案