By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

HI, a question on #include

P: n/a
Hi, all,
I have a question on the use of #include:

#include <unistd.h>
#include <asm/unistd.h>
#include "nn.h"

What are the differences between the above three usages?
It seems the third one allows the code to include the nn.h in the same
directory of the code;
the first one allows the code to include the unistd.h from some other
directory without any specification;
the second one asks the code to include the unistd.h under
somedirectory .../asm/unistd.h.

Then another question is:
If there exist 2 files named unistd.h, one is
..../sys/unistd.h, the other is .../asm/unistd.h, which one will be
included by
#include <unistd.h>

Thanks for your help!

Jing

Mar 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 31 Mar 2006 08:48:33 -0800, "sunnylele" <sj********@gmail.com>
wrote in comp.lang.c:
Hi, all,
I have a question on the use of #include:

#include <unistd.h>
#include <asm/unistd.h>
#include "nn.h"

What are the differences between the above three usages?
It seems the third one allows the code to include the nn.h in the same
directory of the code;
the first one allows the code to include the unistd.h from some other
directory without any specification;
the second one asks the code to include the unistd.h under
somedirectory .../asm/unistd.h.

Then another question is:
If there exist 2 files named unistd.h, one is
.../sys/unistd.h, the other is .../asm/unistd.h, which one will be
included by
#include <unistd.h>

Thanks for your help!

Jing


All the C standard has to say about this is that there are two forms
of the include preprocessor directive. One is:

#include <q-char-sequence>

....and the other is "q-char-sequence".

The standard C headers, 15 in C90, 18 in C95, and 24 in C99, must use
the first form.

It also specifies that for other than the standard C headers, the
directive causes the preprocessor to process the contents of files at
that point in the original file.

Finally it specifies that the <> form causes a search for a file in an
implementation-defined manner. The "" form causes a search for a file
in a (possible different) implementation-defined manner, and if that
search fails, then it searches in the same manner that it will then
search in the manner it does for the <> form.

So it is entirely up to your compiler, operating system, and perhaps
the settings of configuration options what actually happens here. You
need to ask in a group that supports your compiler/OS combination for
specifics on how your compiler behaves.

Perhaps news:comp.os.linux.development.apps or
news:comp.unix.programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Mar 31 '06 #2

P: n/a

"Jack Klein" <ja*******@spamcop.net> wrote in message
news:mb********************************@4ax.com...
On 31 Mar 2006 08:48:33 -0800, "sunnylele" <sj********@gmail.com>
wrote in comp.lang.c:
Hi, all,
I have a question on the use of #include:

#include <unistd.h>
#include <asm/unistd.h>
#include "nn.h"

What are the differences between the above three usages?
It seems the third one allows the code to include the nn.h in the same
directory of the code;
the first one allows the code to include the unistd.h from some other
directory without any specification;
the second one asks the code to include the unistd.h under
somedirectory .../asm/unistd.h.

Then another question is:
If there exist 2 files named unistd.h, one is
.../sys/unistd.h, the other is .../asm/unistd.h, which one will be
included by
#include <unistd.h> The above line will include /sys/unistd.h

To include /sys/asm/unistd.h:
#include <asm/unistd.h>

However, most compilers will allow you to override the order of searches.
So if you used, for example,
cc -L/sys/asm -L/sys ...
then the compiler first looks in /sys/asm
So
#include <unistd.h>
would in this case include the file from /sys/asm

Thanks for your help!

Jing


All the C standard has to say about this is that there are two forms
of the include preprocessor directive. One is:

#include <q-char-sequence>

...and the other is "q-char-sequence".

The standard C headers, 15 in C90, 18 in C95, and 24 in C99, must use
the first form.

It also specifies that for other than the standard C headers, the
directive causes the preprocessor to process the contents of files at
that point in the original file.

Finally it specifies that the <> form causes a search for a file in an
implementation-defined manner. The "" form causes a search for a file
in a (possible different) implementation-defined manner, and if that
search fails, then it searches in the same manner that it will then
search in the manner it does for the <> form.

So it is entirely up to your compiler, operating system, and perhaps
the settings of configuration options what actually happens here. You
need to ask in a group that supports your compiler/OS combination for
specifics on how your compiler behaves.

Perhaps news:comp.os.linux.development.apps or
news:comp.unix.programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Mar 31 '06 #3

P: n/a
"Fred Kleinschmidt" <fr******************@boeing.com> writes:
"Jack Klein" <ja*******@spamcop.net> wrote in message
news:mb********************************@4ax.com...
On 31 Mar 2006 08:48:33 -0800, "sunnylele" <sj********@gmail.com>
wrote in comp.lang.c: [...]
#include <unistd.h>

The above line will include /sys/unistd.h


Why do you assume that the compiler will find the file in /sys?
<OT>On Unix-like systems, include files are more commonly in
/usr/include.</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.