11

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

What is the difference between

#include< >
#include" "

#import< >
#import" "
Community
  • 1
  • 1
Gugan
  • 1,586
  • 1
  • 26
  • 61
  • 3
    I believe, in Objective C? Check this: http://stackoverflow.com/questions/439662/what-is-the-difference-between-import-and-include-in-objective-c – Bijoy Thangaraj Nov 06 '12 at 11:41

4 Answers4

15

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.

Midhun MP
  • 90,682
  • 30
  • 147
  • 191
3

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
justin
  • 101,751
  • 13
  • 172
  • 222
  • So, it isn't like "import refers to a package file(like in java)" and "include refers to local class file" – Gugan Nov 06 '12 at 11:48
  • @user1799919 nope, not like Java here. if you have properly include-guarded all of your headers, you could literally exchange `#include` and `#import` and the files used for discovery would be identical. they do not alter scope or order of search paths. – justin Nov 06 '12 at 11:52
  • @user1799919 you're welcome :) – justin Nov 06 '12 at 11:55
3

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.

  • Hmm thanks i understood the difference between "" and <>. But, import and include still confuses. – Gugan Nov 06 '12 at 11:50
2

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.

Community
  • 1
  • 1
jainvikram444
  • 5,136
  • 1
  • 14
  • 29
  • -1 you shouldn't copy/paste other people's answers. especially if not referenced. the source: http://stackoverflow.com/questions/439662/what-is-the-difference-between-import-and-include-in-objective-c – justin Nov 06 '12 at 11:54
  • may your information every thing avialable is online, and you have whatever knlowledge is also from lerning from book, web ..But main thing is how can you help to person .. – jainvikram444 Nov 06 '12 at 12:03
  • a) very wrong b) also very wrong c) helping people is good, but there are more acceptable ways to do so -- and i figure you already knew this. – justin Nov 06 '12 at 12:24