473,472 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HI, a question on #include

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
3 1432
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

"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
6
by: qaz | last post by:
I run a web site on both a testing server and a "production" server. I noticed that references to the include file do not work on the testing server but they do work on the production server. I...
11
by: enki | last post by:
I am writing a game and I am having trouble with moving the character on the map. Here is what I have right now. It involves win32 programming but that not my problem. I would like some...
5
by: none | last post by:
hi all, (i am running on win 2k pro). i saw a program i like on a website and when i went to download it it was just a load of 'c' code. now, i know very little about 'c' or programming but...
4
by: BSand0764 | last post by:
Apologies for the length of this message, but I'm having problems getting an alternate function to be executed via a functor implementation. I have two classes (BkgLand and BkgWater) that...
3
by: golden | last post by:
Hello, I am going to ask a question regarding write and lseek. I will provide code at the end of this, but first some background. I am trying to identify the cause of some latency in...
25
by: mdh | last post by:
I have looked this up in the FAQ, and still do not have a nice understanding of it. If I have defined a function in foo.c, and if, for the sake of argument have foo.h contain that function's...
9
by: Peskov Dmitry | last post by:
It is a very basic question.Surely i got something wrong in my basic understanding. //Contents of file1.cpp using namespace std; #include <iostream> template <typename T> class my_stack;
25
by: Mark | last post by:
so, i'm making a website. let's say i have header.php, footer.php and content.php. now in index.php I simply want to include the 3 pages. easy enough to do. but let's say the user navigates to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.