Boost是否使用合法的C++预处理指令语法?

Meh*_*dad 13 c++ syntax boost c-preprocessor boost-preprocessor

我的(相对较旧的)C++编译器在Boost中对此文件进行了阻塞,起始时间为:

# /* Copyright (C) 2001
#  * Housemarque Oy
#  * http://www.housemarque.com
#  *
#  * Distributed under the Boost Software License, Version 1.0. (See
#  * accompanying file LICENSE_1_0.txt or copy at
#  * http://www.boost.org/LICENSE_1_0.txt)
#  */
#
Run Code Online (Sandbox Code Playgroud)

这真的是合法的C++吗?预处理器令牌的语法规则是什么?

ybu*_*ill 22

是的,#标准§16[cpp]明确允许仅包含和空格的行:

control-line:
   # includepp-tokens new-line
   # defineidentifier replacement-list new-line
   # defineidentifier lparen identifier-list opt) replacement-list new-line
   # defineidentifier lparen ... )replacement-list new-line
   # defineidentifier lparen identifier-list , ... )replacement-list new-line
   # undefidentifier new -line
   # linepp-tokens新线
   # errorpp-tokens 选择新线
   # pragmapp-tokens 选择新线
   #新线

请注意,注释将在转换阶段3(即预处理器之前)由空格替换.

  • @LieRyan:查看链接的文件.作者认为使用`#`更容易在文件中启动*all*行.这只是一种编码风格.我个人不喜欢它. (5认同)
  • 为什么增强注释并添加空白预处理器令牌?这样做有什么好处,而不是只使用简单的常规块注释? (4认同)
  • @Nawaz:OP询问"预处理器令牌语法的规则是什么",因此提供一些上下文不会受到伤害. (3认同)