C++11 - GCC - Can #import (used once) replace many #include? (or is that necessary?)

45 views Asked by At

I was reading at C++ #include and #import difference.

It says that #import includes a file only if it hasn't been included before.

I have been finding, in some code like OpenCV, the exact same #include in many of their files. That repetition did not seem necessary to me. I thought that it would be better to simply use each #include only one time in one beginning header collection file. Now, I am reading about #import. I am wondering that if every time that #include is used, in different files in the same program, for the same header file, that it might cause the code to become larger and the executable to become larger and maybe make a longer compile time.

Example:

  • The file1.h has #include <math.h>.
  • The file2.h has #include <math.h>.
  • The file3.h has #include <math.h>.

If file1.h is used first, then it's #include <math.h> should be suffice for file2.h and file3.h.

If file1.h and file2.h and file3.h all have the same #include <math.h>, that seems to be placing an extra load on the compiler and maybe worse.

If multiple occurrences of the same #include cause problems, then would replacing them all with #import?

Can #import (used once) replace many #include? (or is that necessary?)

0

There are 0 answers