0

Just new to learning c++. My understanding to date is that when I include the <iostream> header file at the beginning of my program, the program can use any of the functions that come with the header file, ie. cerr, cin, clog, cout, wcerr, wcin, wclog, wcout.

  1. If my program only uses cin and cout, will it still contain the other functions after compile, even if they are not used or needed?
  2. And if those unused functions are included at compile time, won't this tend to add "bloat" to my program?
  3. Or does the include statement just tell the compiler where to look for those 8 functions, but then the compiler just grabs the function information only on the cin and cout that are actually written in the main function?

I can't find any information as to what exactly gets included to a program when a header file is used.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
sub200
  • 1
  • Possible duplicate of [Do unused functions get optimized out?](https://stackoverflow.com/questions/6215782/do-unused-functions-get-optimized-out) – user202729 Aug 15 '19 at 08:44
  • By the way `cin` and other streams are not functions, they are objects. The `operator>>` for example are functions. – user202729 Aug 15 '19 at 08:45

1 Answers1

2

All the code in the header is included in your program, but, this is not as bad as it sounds: most compilers and linkers can do an optimization called "dead code elimination", where they remove unused code.

There is still a downside though: the increase in time it takes to compile your program due to the additional code.

Catfish_Man
  • 41,261
  • 11
  • 67
  • 84