Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ "#include" output explanation

Tags:

c++

gcc

g++

Trying to understand how #include works. I'm reading that, during pre-procesing, it just replaces itself with the contents of the referenced file.

To verify, I create two files. A file named otherfile containing only the string 1234, and a file test.cpp which contains

#include otherfile
abcd

I run g++ -E test.cpp, and the output I get is

# 1 "test.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 373 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test.cpp" 2
# 1 "./wtf" 1
1234
# 2 "test.cpp" 2
abcd

Where do the rest of the lines come from, and what do they mean?

like image 361
blue_note Avatar asked Mar 12 '19 13:03

blue_note


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

Where do the rest of the lines come from

They are added by the pre-processor.

and what do they mean?

As per the documentation

Source file name and line number information is conveyed by lines of the form

# linenum filename flags

These are called linemarkers. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file filename at line linenum. filename will never contain any non-printing characters; they are replaced with octal escape sequences.

like image 143
eerorika Avatar answered Oct 01 '22 13:10

eerorika