Previous in Forum: Excel Function   Next in Forum: Is Vista Really a Pig?
Close
Close
Close
3 comments
Rate Comments: Nested
Participant

Join Date: Dec 2007
Posts: 1

c++

12/05/2007 11:58 PM

In a C compiler, Is it necessary to include header files to our code in order to use functions in those header files?

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
The Architect
Engineering Fields - Software Engineering - S/W Architect Popular Science - Evolution - Fascinating! Fans of Old Computers - TRS-80 - A fine computer United States - US - Statue of Liberty - NY

Join Date: Dec 2004
Location: GlobalSpec, Troy NY
Posts: 386
Good Answers: 5
#1

Re: c++

12/07/2007 9:08 AM

Yes, header files are needed to provide the declarations for any functions defined outside of the current "compilation unit" (single a ".c" or ".cpp" file). The exception to that rule is if you include the declarations (that would normally go in a header file) in the compilation unit itself, but that isn't terrible useful/good in most cases.

There are tools to automatically create header files from .c files but it's been a while since I did C/C++ programming so I don't know what's available now, and I presume it would depend on your OS.

Thanks
- Mark

__________________
Mark Gaulin
Register to Reply
Associate
United States - Member - New Member

Join Date: Nov 2007
Location: Land of Ahs
Posts: 36
#2

Re: c++

12/07/2007 12:51 PM

Yes, the compiler must be able to find the modules from the headers you are referencing. Those header files contain modules/functions that allow you to use the standard coding references. One way I used to like to do that is in an included file. All header files are listed in the included file. It always seemed nice and neat in the code w/o the huge header. Also you can make that file a standard part of your repertoire, bookshelfed. Just a consideration.

__________________
Is it possible to float on light waves?
Register to Reply
Guru

Join Date: Sep 2006
Posts: 4513
Good Answers: 88
#3

Re: c++

12/07/2007 8:22 PM

Is it necessary (ie, is it strictly required by the language definition)?

No. Anything that can be declared/defined inside a header file can be declared/defined inside the (.c) source file itself. You are not strictly required to use header files. (Why you would chose not to include the file when it would be clearly to your advantage to do so is an entirely different issue altogether).

Is it recommended/preferable? Yes. Nearly always. (But as with everything else, there are exceptions.)

Register to Reply
Register to Reply 3 comments
Copy to Clipboard

Users who posted comments:

mgaulin (1); RidetheWave (1); user-deleted-13 (1)

Previous in Forum: Excel Function   Next in Forum: Is Vista Really a Pig?
You might be interested in: Bar Code Scanners, Bar Code Cards, Bar Code Software

Advertisement