delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/17:42:33

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: .h files unrecognised
Date: Mon, 16 Feb 1998 21:38:09 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 57
Message-ID: <34E8F811.3E1D@cs.com>
References: <34E59182 DOT 80F AT which DOT net> <34E5D9D3 DOT 5C94 AT cs DOT com> <+gId1FA6c350EwVR AT robchris DOT demon DOT co DOT uk>
NNTP-Posting-Host: ppp242.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Rob wrote:
> 
> In article <34E5D9D3 DOT 5C94 AT cs DOT com>, John M. Aldrich <fighteer AT cs DOT com>
> writes
> [...]
> >Under no circumstances should you write your program in the same
> >directory as the system headers, nor should you copy the system headers
> >into your program's directory.
> [...]
> Why not? And does this extend to .h or .hpp files one writes oneself?

System headers should generally be considered part of the compiler. 
It's considered very bad programming practice to mix them with your own
source code, for many reasons:

 - Your code loses all advantages of portability, to the point of being
totally unusable on any other compiler, or even any other computer
running the same compiler.
 - Your code becomes extremely difficult to debug.
 - The syntax of C/C++ is designed to keep the system headers separate
from your own by using <> brackets instead of double quotes to refer to
them.
 - Compiler updates may change the system headers without notice,
destroying any modifications you make and potentially overwriting your
own code.
 - If you delete the compiler but keep your programs, you'll have to
sort out your code from the compiler's.

The proper syntax for writing programs is to refer to standard includes
with <>, and put any definitions specific to your program in header
files that you create yourself and refer to with "".

> I can't get RHIDE to link such .hpp files into the .cpp file in a
> project; the linker stage simply produces crazy errors and an apparently
> empty (but error-filled) file called: [whatever].cc. It doesn't matter
> as I can still write, compile and link files with the same content under
> djgpp direct in DOS. But why is this happening under the otherwise
> excellent RHIDE?

The purpose of the #include directive is to instruct the preprocessor to
find a file and insert its code into your source.  You do NOT need to
add header files to a project; doing so causes RHIDE to attempt to
compile them as source code, which doesn't work and can lead to major
errors.

BTW, the standard extension for headers is '.h'.  '.hpp', AFAIK, is
nonstandard, although I could be wrong.

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>  UIN# 7406319

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? C++>$ U@>++$ p>+ L>++ E>++ W++ N++ o+>++ K? w(---)
O- M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+(++) tv+() b+++ DI++ D++ G>++
e(*)>++++ h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019