473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Header files

ben
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?

Next where can i find definition of functions defined in system header
files. I'm working on UNIX.

Thanx in advance.

--ben

Nov 8 '06 #1
7 2155
ben wrote:
I have few doubts about header files.
Is it true that header files always have only "function declaration"
and not definition?
No.

But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
Next where can i find definition of functions defined in system header
files.
Why do you want them? Do you really want the definitions, or just a
description?
I'm working on UNIX.
(a) Typically those functions are described on manpages with staggeringly
obvious names.

(b) Different Unices will have those function definitions in different
places. If they ship them at all. They need not.

(c) There are publicly available sources for implementations of those
functions (note: not necessarily the ones on your Unix), eg and
in particular, glibc.

(d) Google is your nasal demon. I mean friend.

--
Chris ".enable proofreading" Dollin
Meaning precedes definition.

Nov 8 '06 #2


ben wrote On 11/08/06 10:23,:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
Usually true, but not "always" true.
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
One of the virtues of the "separate compilation" model
used by C and some other programming languages is that once
the "source code" has been compiled into "object code," you
no longer need the source: You just "link" the object code
from several compilations together, and there's your program.

Many systems take advantage of this ability to reduce the
amount of disk space needed: object code is usually much
smaller than source code, and since the object code is all
that's needed to run the program, why waste space on the
bulky source? Some Unix and non-Unix system providers may
also withhold the source code for commercial and licensing
reasons (or maybe to spare themselves embarrassment). The
upshot is that on many systems the source code won't be
present at all, or may be an "optionally installable" part
of the system distribution. On some systems, you may be
able to get the source code only by paying for it (and,
probably, by agreeing not to reveal it).

If the source for your system's libraries is available,
its location and form will be entirely system-dependent and
not dictated by the C language. (Indeed, the libraries might
not be written in C at all.) Try your question on a forum
dedicated to the particular Unix flavor you are interested in.

--
Er*********@sun.com

Nov 8 '06 #3

ben wrote:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
There is no hard and fast rule which say this. However, it is the
general
practice (for very good reasons) and in some cases it is required. For
instance, if you have a static variable declared and defined in a
header
file, and you include this header file in multiple *.c files, you may
get a
compilation error.
>
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
I am not sure about this one, I haven't looked for the source code. I
believe, if
you have open source version of libraries, while downloading you will
need to
specify to download the source code along with the libraries.
>
Thanx in advance.

--ben
Nov 8 '06 #4

ben wrote:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
Not necessarily, but in general it's a good practice for several
reasons.

First of all, header files can wind up being #included multiple times
in the same translation unit (this often happens when header files
include other header files). Multiple definitions of the same function
in the same translation unit will cause the compiler to complain (it is
possible to avoid this problem with guard macros).

Secondly, if the header is included in several translation units, each
translation unit will have a redundant definition of that function.
Some linkers will resolve the redundant definitions into a single
definition, some may not. Some may complain about the redundant
definitions. If nothing else, the redundant definitions take up space.
If a function needs to be shared between multiple translation units,
it's better to put the function definition in a translation unit of its
own, compile it separately, and link it as necessary. That way, it
only needs to be compiled once (as opposed to once for every
translation unit that includes it), and you don't have to worry about
linker behavior.

Life is easiest when header files describe interfaces, not
implementations. There's really nothing stoppping you from putting a
function definition in a header file, but most of the time it will lead
to heartburn.
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
The actual source code may not be available for your implementation,
and if it is, it may vary widely between implementations. If you want
to see some examples of how the standard library functions *may* be
implemented, find P. J. Plauger's "The Standard C Library."

Nov 8 '06 #5
In article <ei*********@malatesta.hpl.hp.com>,
Chris Dollin <ch**********@hp.comwrote:
>Is it true that header files always have only "function declaration"
and not definition?
>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 8 '06 #6
Richard Tobin wrote:
In article <ei*********@malatesta.hpl.hp.com>,
Chris Dollin <ch**********@hp.comwrote:
>>Is it true that header files always have only "function declaration"
and not definition?
>>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).

There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.
I'll grant that.

--
Chris ".enable proofreading" Dollin
"Who do you serve, and who do you trust?" /Crusade/

Nov 9 '06 #7
ben
Thanks to all for ur answers.

--
Ben
Chris Dollin wrote:
Richard Tobin wrote:
In article <ei*********@malatesta.hpl.hp.com>,
Chris Dollin <ch**********@hp.comwrote:
>Is it true that header files always have only "function declaration"
and not definition?
>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.

I'll grant that.

--
Chris ".enable proofreading" Dollin
"Who do you serve, and who do you trust?" /Crusade/
Nov 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... ...
21
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds...
16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
11
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
18
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module...
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
36
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.