gcc和微软preprocessor之间的区别 [英] Difference between gcc and Microsoft preprocessor

查看:149
本文介绍了gcc和微软preprocessor之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,微软的Visual Studio编译器和GCC preprocess以下的小片断是不同的:

 #定义M3(X,Y,Z)X + Y + Z
#定义M2(X,Y)的M3(X,Y)
#定义的P(X,Y){X,Y}
#定义的M(X,Y)M 2(X,P(X,Y))
M(A,B)

GCC -E给出了如下的:

  A + {A + B}

,而CL / E'问题的有关丢失宏参数,并产生下列输出警告:

  A + {A,B} +

似乎从嵌套宏扩展来逗号不被认为是参数分割。不幸的是,我没有发现在CL preprocessor实现的算法的描述,所以我不知道,我的建议是正确的。有谁知道如何CL preprocessor作品,什么是它的算法和gcc的区别?以及如何观察到的行为可以解释?


解决方案

 #定义M3(X,Y,Z)X + Y + Z
#定义M2(X,Y)的M3(X,Y)
#定义的P(X,Y){X,Y}
#定义的M(X,Y)M 2(X,P(X,Y))
M(A,B)

让我们手动还原了这一点,一步一步:

  M(A,B)
- > M2(A,P(A,B))
- > M2(一,{A,B})

标准说:


  

在列表中的各个参数之间用逗号分隔
   匹配括号内不分开的preprocessing令牌,但逗号preprocessing标记


只是括号中所提到的,所以......

   - > M3(一,{A,B})
- >一个+ {A + B}

重要提示:

  M3(A,{A,B})

下面,根据从标准previous报价,三个参数被传递至M3(使用单引号来描述令牌/参数):

  M3('A','{A,B}')

这是扩大到

 '一个'+'{一个'+'B}'

这是什么 CPP (4.6.1)给出逐字:

 #1cpp.cpp
#1<内置>中
#1<命令行>中
#1cpp.cpp
一个+ {A + B}

CPP (或 GCC G ++ )是正确的,MSVC是没有的。

作为一个贵族确保bug报告存在。

I discovered that Microsoft Visual Studio compiler and gcc preprocess the following small snippet differently:

# define M3(x, y, z) x + y + z
# define M2(x, y) M3(x, y)
# define P(x, y) {x, y}
# define M(x, y) M2(x, P(x, y))
M(a, b)

'gcc -E' gives the following:

a + {a + b}

, while 'cl /E' issues a warning about missing macro argument and produces the following output:

a + {a, b} +

It seems that commas that came from nested macro expansions are not considered to be argument separators. Unfortunately, I found no description of the algorithm implemented in cl preprocessor, and so I'm not sure that my suggestion is correct. Does anyone know how cl preprocessor works and what's the difference between its algorithm and gcc's? And how the observed behaviour can be explained?

解决方案

# define M3(x, y, z) x + y + z
# define M2(x, y) M3(x, y)
# define P(x, y) {x, y}
# define M(x, y) M2(x, P(x, y))
M(a, b)

Let us roll this out manually, step by step:

M(a, b)
--> M2(a, P(a, b))
--> M2(a, {a, b})

The standard says:

The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens between matching inner parentheses do not separate

only parentheses are mentioned, so ...

--> M3(a, {a, b})
--> a + {a + b}

Important:

M3(a, {a, b})

Here, according to the previous quote from the standard, three "arguments" are passed to M3 (using single-quotes to describe tokens/arguments):

M3('a', '{a', 'b}')

which are expanded to

'a' + '{a' + 'b}'

And this is what cpp (4.6.1) gives verbatim:

# 1 "cpp.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "cpp.cpp"




a + {a + b}

cpp (or gcc and g++) are correct, MSVC isn't.

As a nobleman make sure a bug report exists.

这篇关于gcc和微软preprocessor之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆