Is Boost using legal C++ preprocessing directive syntax?
Asked Answered
M

1

13

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?

Maggy answered 11/8, 2012 at 7:24 Comment(4)
Oh no! Don't tell me you use Turbo C++ too!!Pinsk
@CodyGray: Heavens, no! It was an old VC compiler.Maggy
What version, VC 4.0? I'm curious why can't you upgradeBoresome
@Viet: 6.0. It was just a compatibility test for a library; I've already upgraded.Maggy
U
22

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.

Unfounded answered 11/8, 2012 at 7:28 Comment(6)
+1. The last one is all that I was looking for, and actually answers the question : # new-line.Warrin
@Nawaz: the OP asks "What's the rule on the syntax of preprocessor tokens" so providing some context won't hurt.Unfounded
@Nawaz: Haha take a look at the edit history on my post, it was amusing. :)Maggy
@Mehrdad: Haha.. we were doing the same thing at the same time, hence SO merged them.Warrin
Why is boost commenting and adding blank preprocessor token? Is there any advantage in doing that instead of using just simple regular block comment?Pamphylia
@LieRyan: look at the file linked in question. The author decided that it is easier to start all lines in the file with #. It's just such a coding style. Personally I don't like it.Unfounded

© 2022 - 2024 — McMap. All rights reserved.