HI, a question on #include

S

sunnylele

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
 
J

Jack Klein

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 or
 
F

Fred Kleinschmidt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top