Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ include and import difference

What is the difference between #include and #import in C++?

like image 497
Marius Avatar asked Oct 05 '08 16:10

Marius


People also ask

What is the difference between import and include in Objective-C?

#import and #include are preprocessor directives for bringing in the contents of a header to a file. #include is replaced by the contents of the header directly, while #import is only replaced by the contents of the header the first time that header is imported.

What is the difference between #import and #include in C++?

#import is a Microsoft-specific thing, apparently for COM or . NET stuff only. #include is a standard C/C++ preprocessor statement, used for including header (or occasionally other source code) files in your source code file.

What is the import statement in C?

import statement makes the JVM go to the Java standard library, execute the code there , and substitute the result into the program. Here, no code is copied and hence no waste of memory or processor's time. hence import is an efficient mechanism than #include.

What is difference between #include <> and #include?

The difference between the two types is in the location where the preprocessor searches for the file to be included in the code. #include<> is for pre-defined header files.


1 Answers

Import in VC++: #import is for type libraries or .tlbs (COM stuff).

The content of the type library is converted into C++ classes, mostly describing the COM interfaces for you automatically, and then it is included into your file.

The #import directive was introduced by Microsoft as an extension to the C++ language. You can read about it at this MSDN article.

The #import directive is also used with .NET / CLI stuff.

Import in gcc: The import in gcc is different from the import in VC++. It is a simple way to include a header at most once only. (In VC++ and GCC you can do this via #pragma once as well)

The #import directive was officially undeprecated by the gcc team in version 3.4 and works fine 99% of the time in all previous versions of gcc which support

Include: #include is for mostly header files, but to prepend the content to your current file. #include is part of the C++ standard. You can read about it at this MSDN article.

like image 152
Brian R. Bondy Avatar answered Sep 24 '22 05:09

Brian R. Bondy