Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

'import' in Java vs. '#include' in C/C++

Does 'import' in Java behave in the same way as '#include' in C/C++? Specifically, will it include the entire library that it is importing or will it just include the classes and methods that are called in the subsequent code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

#include does none of both, neither "importing" libraries, nor classes or modules.

The #include directive just tells the pre-processor to include the contents of another text file (source). That's all.

The result of pre-processing file A #includeing file B is passed to the compiler as if they were one file, with file B pasted into file A at the position where the #include directive was placed.

To expliclity state this: This all happens prior to any compilation, code generation.

As a side effect the C/C++ pre-processor could be used independently from the compiler to process any kind of text file input.

One could argue that pre-processor statements like #include "are not really part of the C/C++ languages", as they are not essentially needed to write any programs in C/C++, as they are never passed to the compiler.

The expression import is not used in the context of (standard) C/C++ programming, as there is nothing to be imported.

C/C++ modules are put together either on source level prior to compilation or by the linker after compilation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...