Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Header Inclusion style

Reply
Thread Tools

Header Inclusion style

 
 
qazmlp
Guest
Posts: n/a
 
      07-08-2003
If I include the headers(.h files) like
#include "myHeader.h",
in my implementation file(.C file), then 'myHeader.h' is properly
included. But, when I include it like
#include <myHeader.h>, Compiler gives an error.

What setting do I need to do such that, the latter syntax also accepted
for my headers ?
 
Reply With Quote
 
 
 
 
Bertrand Mollinier Toublet
Guest
Posts: n/a
 
      07-08-2003
qazmlp wrote:
> If I include the headers(.h files) like
> #include "myHeader.h",
> in my implementation file(.C file), then 'myHeader.h' is properly
> included. But, when I include it like
> #include <myHeader.h>, Compiler gives an error.
>
> What setting do I need to do such that, the latter syntax also accepted
> for my headers ?


[replied only in c.l.c]

None that you should know about. The latter syntax is reserved for
standard headers (in the ISO C meaning of the term), and any header your
implementation is willing to consider standard.

Your own headers are your own only, and should always be included with
the #include "foo.h" syntax.

--
Bertrand Mollinier Toublet
"Reality exists" - Richard Heathfield, 1 July 2003

 
Reply With Quote
 
 
 
 
Floyd Davidson
Guest
Posts: n/a
 
      07-08-2003
(qazmlp) wrote:
>If I include the headers(.h files) like
>#include "myHeader.h",
>in my implementation file(.C file), then 'myHeader.h' is properly
>included. But, when I include it like
>#include <myHeader.h>, Compiler gives an error.
>
>What setting do I need to do such that, the latter syntax also accepted
>for my headers ?


The <...> notation finds headers "in the standard places", hence
system headers, as opposed to those that you provide, will be
found.

The "..." notation probably looks in the current working
directory first, and will thus include headers you provide,
before looking in the same places that <...> will look.

That means you probably want to use the different notations
thusly,

#include <stdio.h> /* header provided by the platform */
#include "myhdr.h> /* header provided by the program */

With unix style compilers you also have the option of adding to
the places the compiler thinks of as "standard", usually with
the -I option. Hence invoking the compiler with '-I./include'
will cause the <...> notation to also look in the ./include
directory for headers.

You'll definitely want to read the documentation for your
compiler. You can also look for an option that will tell you
more about what it is doing. For example, with the GNU C
compiler, gcc, you can give it the -v option and it will
verbosely explain what it is doing and where it is searching for
headers (and libraries, and whatever).

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)
 
Reply With Quote
 
Darrell Grainger
Guest
Posts: n/a
 
      07-08-2003
On 7 Jul 2003, qazmlp wrote:

> If I include the headers(.h files) like
> #include "myHeader.h",
> in my implementation file(.C file), then 'myHeader.h' is properly
> included. But, when I include it like
> #include <myHeader.h>, Compiler gives an error.
>
> What setting do I need to do such that, the latter syntax also accepted
> for my headers ?


The places searched are implementation defined for both formats. You'd
have to consult your compiler documentation to find out where it searches
for the different headers.

Typically, #include <file.h> will search the system header files and
#include "file.h" will search the project header files and then the system
header files.

Why is it important that you use #include <file.h> to find your header
files? If I looked at your source code I would assume the header file is
an implementation specific header file for a certain compiler. It would
not immediately occur to me that it was a project header file. When I see
#include "file.h" I immediately think this is a file created by the
project programmer and not the compiler company. This is all jut
convention but having conventions makes it easier for you to work with
others.

--
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}

 
Reply With Quote
 
JCB
Guest
Posts: n/a
 
      07-08-2003
(qazmlp) wrote in message news:< om>...
> If I include the headers(.h files) like
> #include "myHeader.h",
> in my implementation file(.C file), then 'myHeader.h' is properly
> included. But, when I include it like
> #include <myHeader.h>, Compiler gives an error.
>
> What setting do I need to do such that, the latter syntax also accepted
> for my headers ?



I don't think you can.
If it was the case, your program will be less clear, because less easy
to distinguish beetween standard headers and "personnal" headers.

Just one question : why do you want to use the <file.h> syntax with
your personal headers ???
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      07-08-2003
Floyd Davidson <> writes:

> #include "myhdr.h> /* header provided by the program */


Is that a joke?
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      07-08-2003


qazmlp wrote:
>
> If I include the headers(.h files) like
> #include "myHeader.h",
> in my implementation file(.C file), then 'myHeader.h' is properly
> included. But, when I include it like
> #include <myHeader.h>, Compiler gives an error.



This guy just HAS to be trolling. He's supposedly been studying C and
C++ for over a year now, he's posted dozens if not hundreds of questions
to various groups, all of them these simplistic matters that he could
have figured out by reading the books he claims to own or from a brief
google search.




Brian Rodenborn
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      07-08-2003
In 'comp.lang.c', (qazmlp) wrote:

> If I include the headers(.h files) like
> #include "myHeader.h",
> in my implementation file(.C file), then 'myHeader.h' is properly
> included. But, when I include it like
> #include <myHeader.h>, Compiler gives an error.


Good.

> What setting do I need to do such that, the latter syntax also accepted
> for my headers ?
>


The <> headers are reserved for the implementation (standard or not).
The "" headers are reserved for the user's headers.

--
-ed- [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      07-08-2003
In 'comp.lang.c', Dave Uhring <> wrote:

> On Mon, 07 Jul 2003 23:59:02 -0700, qazmlp wrote:
>
>> If I include the headers(.h files) like
>> #include "myHeader.h",
>> in my implementation file(.C file), then 'myHeader.h' is properly
>> included. But, when I include it like
>> #include <myHeader.h>, Compiler gives an error.

>
> "myHeader.h" without that comma is in the current working directory.


This is completely implementation dependent.

> <myHeader.h> is in /usr/include or one referenced by some -I/directory or
> -isystem /somedirectory.


This is completely implementation dependent.

The good reason was exposed already on the other posts.

<> -> implementation
"" -> user

--
-ed- [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
 
Reply With Quote
 
Dave Uhring
Guest
Posts: n/a
 
      07-08-2003
On Tue, 08 Jul 2003 19:28:11 +0000, Emmanuel Delahaye wrote:

> This is completely implementation dependent.
>
> The good reason was exposed already on the other posts.
>
> <> -> implementation
> "" -> user


Works the same way with gcc and Solaris cc. What is your point?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in inclusion of header files vector.h,map.h.. kpoan C++ 0 08-15-2006 03:38 AM
tool to check multiple inclusion of header file techBoy C Programming 6 03-15-2006 10:49 AM
Header inclusion question Johannes Bauer C++ 6 12-08-2004 02:53 AM
C++ Header Inclusion Matthew Burgess C++ 2 08-28-2003 08:16 PM
[C++] Order of header inclusion qazmlp C++ 9 08-25-2003 05:12 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57