From: Rob Newsgroups: comp.os.msdos.djgpp Subject: Re: .h files unrecognised Date: Tue, 17 Feb 1998 20:56:47 +0000 Organization: Spinner Message-ID: <+AZ+QBAPmf60EwPb@robchris.demon.co.uk> References: <34E59182 DOT 80F AT which DOT net> <34E5D9D3 DOT 5C94 AT cs DOT com> <+gId1FA6c350EwVR AT robchris DOT demon DOT co DOT uk> <34E8F811 DOT 3E1D AT cs DOT com> NNTP-Posting-Host: robchris.demon.co.uk MIME-Version: 1.0 Lines: 67 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article <34E8F811 DOT 3E1D AT cs DOT com>, John M. Aldrich writes >Rob wrote: >> >> In article <34E5D9D3 DOT 5C94 AT cs DOT com>, John M. Aldrich >> 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 "". Thank you very much for the explanation. > >> 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. I had misunderstood what projects in RHIDE were for. RHIDE tends to put files into one project unless you tell it not to. Many thanks for putting me straight on this. > >BTW, the standard extension for headers is '.h'. '.hpp', AFAIK, is >nonstandard, although I could be wrong. Jesse Liberty's TYC++in24Hrs uses the .hpp suffix for files used to store class declarations (interfaces), which the .cpp file will #include, and which will in turn #include . (This chain was why I thought the .hpp files had to be compiled in the project). Hour 7 is where I'm at and I'll be lucky to make sense of everything first time round! > Thanks a 3rd time. Robert Christie Spinner & Crisis, an exploration of 64-year and related cycles in history, at: http://www.robchris.demon.co.uk/Spinner "I may be paranoid, but that doesn't mean they're not out to get me."