BenC
BenC

Reputation: 8976

What do gcc preprocessed output lines of form hash sign + digit "# 1" mean?

While doing a bug report for CUDA's compiler, I ended up finding this strange behavior with gcc's preprocessing step. I currently use gcc 4.8.2.

Test file: test.cpp

#include <assert.h>

int main()
{
    int a = 1;
    assert (a >= 0);
    assert (a
            >= 0);
}

Command

gcc -E -x c++ -m64 -g -o "test.cpp4.ii" "test.cpp"

Result file: test.cpp4.ii

# 2 "test.cpp" 2

int main()
{
    int a = 1;
    ((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0", "test.cpp", 6, __PRETTY_FUNCTION__));
    ((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0",
 "test.cpp"
# 7 "test.cpp" 3 4
    ,
 8
# 7 "test.cpp" 3 4
    , __PRETTY_FUNCTION__))
                 ;

The multiline assert seems to be processed differently, leading to these # 7 "test.cpp" 3 4 lines. What does that mean exactly?

Update

Apparently, gcc 4.7 gives # 7 "test.cpp" (without the last 2 numbers).

Upvotes: 4

Views: 1184

Answers (1)

MSalters
MSalters

Reputation: 180303

It looks like line markers. As you might have noted, there's no trivial relation between line numbers in the original and preprocessed file. # 7 in the preprocessed input indicates that the source of next line was line7 in the original (which was named test.cpp).

3 4 are flags, meaning "macro expansion from system header" and extern "C"

GCC documentation

Upvotes: 5

Related Questions