What is the purpose of a single pound/hash sign (#) on its own line in the C/C++ preprocessor?

callyalater picture callyalater · Feb 4, 2016 · Viewed 14.2k times · Source

I have been looking at the Boost libraries source code, and I have noticed that often there are single pound signs without any preprocessor directives attached to them. I read through the GCC preprocessor manual and specification guide and can't find anything about it.

(1) #ifndef BOOST_CONFIG_HPP
(2) #  include <boost/config.hpp>
(3) #endif
(4) #
(5) #if defined(BOOST_HAS_PRAGMA_ONCE)
(6) #  pragma once
(7) #endif

On line 4, there is nothing after the pound sign. What effect does this have? Is it defined in the C preprocessor (CPP) specification?

As Boost is a cross-platform library, I would assume that any CPP should parse it correctly. What would the effect/side-effects be of having random pound/hash signs throughout the code?

Answer

Jonathan Wakely picture Jonathan Wakely · Feb 4, 2016

A # on its own on a line has no effect at all. I assume it's being used for aesthetic value.

The C standard says:

6.10.7 Null directive

Semantics

A preprocessing directive of the form

# new-line

has no effect.

The C++ standard says the same thing:

16.7 Null directive [cpp.null]

A preprocessing directive of the form

# new-line

has no effect.