Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between includes and imports [duplicate]

Possible Duplicate:
What is the difference between #import and #include in Objective-C?

What is the difference between

#include< >
#include" "

#import< >
#import" "
like image 415
Gugan Avatar asked Nov 06 '12 11:11

Gugan


4 Answers

The #import directive is an improved version of #include. #import ensures that a file is only ever included once so that you never have a problem with recursive includes.

#import "" first check the header in project folder then goes to system library, and the #import<> checks for system headers". In theory the locations are compiler defined and they could be implemented differently on a given platform.

like image 185
Midhun MP Avatar answered Oct 22 '22 06:10

Midhun MP


When using #import, the header include guard is unnecessary. Otherwise, it's just like #include.

The header include guard, seen in C and C++ files:

#ifndef HGUARD_MONHeader_h
#define HGUARD_MONHeader_h

...header contents...

#endif
like image 36
justin Avatar answered Oct 22 '22 05:10

justin


import is super set of include, it make sure file is included only once. this save you from recursive inclusion. about "" and <>. "" search in local directory and <> is use for system files.

like image 28
Muhammad Usman Aleem Avatar answered Oct 22 '22 05:10

Muhammad Usman Aleem


The #import directive was added to Objective-C as an improved version of #include. Whether or not it's improved, however, is still a matter of debate. #import ensures that a file is only ever included once so that you never have a problem with recursive includes. However, most decent header files protect themselves against this anyway, so it's not really that much of a benefit.

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

#include and #import request that the preprocessor* read a file and add it to its output. The difference between #include and #import is that

#include allow you to include the same file many times. #import ensures that the preprocessor only includes a file once. C programmers tend to use #include. Objective-C programmers tend to use #import.

* Compiling a file in Objective-C is done in two passes. First,
the preprocessor runs through the file. The output from the preprocessor goes into the real compiler.

like image 2
jainvikram444 Avatar answered Oct 22 '22 06:10

jainvikram444