Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Boost using legal C++ preprocessing directive syntax?

My (relatively old) C++ compiler choked on this file in Boost, which starts out as:

# /* 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)
#  */
#

Is this really legal C++? What's the rule on the syntax of preprocessor tokens?

like image 320
user541686 Avatar asked Aug 11 '12 07:08

user541686


1 Answers

Yes, a line containing only # and whitespace is explicitly permitted by the standard §16 [cpp]:

control-line:
   # include pp-tokens new-line
   # define identifier replacement-list new-line
   # define identifier lparen identifier-listopt) replacement-list new-line
   # define identifier lparen ... ) replacement-list new-line
   # define identifier lparen identifier-list, ... ) replacement-list new-line
   # undef identifier new-line
   # line pp-tokens new-line
   # error pp-tokensopt new-line
   # pragma pp-tokensopt new-line
   # new-line

Note that comments are replaced by whitespace at translation phase 3, that is before the preprocessor.

like image 199
Yakov Galka Avatar answered Oct 08 '22 15:10

Yakov Galka