Abdullahismael's blog

By Abdullahismael, history, 6 weeks ago, In English

I had this question in my mind, does the compiler tree shakes or delete the unused code from these headers and is it time consuming to parse the file and do the tree shaking or it's neglectable

  • Vote: I like it
  • +7
  • Vote: I do not like it

»
6 weeks ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

in real life: it's bad practice and you shouldn't do it

in competitive programming: it's perfectly fine and you should use it

»
6 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

For contest it is necessary.

But for understanding what is going on it is a must to know what headers you need for a particular in-built fuction and you don't have to worry as it is not that difficulty to know, most are very intuitive.

»
6 weeks ago, hide # |
Rev. 2  
Vote: I like it +11 Vote: I do not like it

Yes. A header file only contains stubs that tell the compiler what each function means; it's actually the linker that has to resolve the references and load the functions you use. (The linker is smart. If you include a header with 500 function declarations but only use 10 of them, the linker will only link to the 10 you use.)

And, I believe most STL libraries are shared objects, so they are loaded into memory once by the OS and dynamically linked at runtime. This happens only once and probably takes less than a few microseconds.

»
6 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Yes its the best practice to use in cp. But make sure to precompile the header to save time in each compilation.

  • »
    »
    6 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I was about to comment this; precompiled headers are really good if you have an underpowered computer. My compilation time dropped from about 3s to 1s after I started using them.