Блог пользователя Abdullahismael

Автор Abdullahismael, история, 6 месяцев назад, По-английски

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

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +11 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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