0

Is there any difference between using the include directive versus externing everything?

In Cpp, is externing all of the functions and variables and later, compiling and linking both my source and the header files the *same* as including it and using its members?

3rd Oct 2024, 3:57 PM
Calvin Jude
Calvin Jude - avatar
4 ответов
+ 2
Calvin Jude your notions are all correct. Using extern indicates to the compiler that it may have to backpatch the function reference after it locates the function definition externally, but the eventual result is the same as #include of the function source or function prototype. Using #include does simply insert the include file text into your source as part of preprocessing before compiling.
3rd Oct 2024, 7:01 PM
Brian
Brian - avatar
0
What exactly does the #include directive do? Does it paste the header's text in the source file and then feed it to the compiler?
3rd Oct 2024, 3:57 PM
Calvin Jude
Calvin Jude - avatar
0
Brian I've been reading more about header files and noticed that most of them mainly contain forward declarations for functions, with their actual implementations located in separate files. Does this also apply to iostream? If so, how is the corresponding implementation file automatically compiled and linked?
4th Oct 2024, 2:22 AM
Calvin Jude
Calvin Jude - avatar
0
Do all standard headers only contain prototypes?
4th Oct 2024, 2:23 AM
Calvin Jude
Calvin Jude - avatar