473,756 Members | 8,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom header files

Hi,

Can someone explain the basic structure of a header file? I just
completed a introductory C programming class. The course stressed
structured programming and creating reusable code. We learned to use
functions and to create our own. The problem is we never learned to
place them in header files. To me, and obviously, I'm not that
experienced with C, it would be better to place user created functions
in separate header files instead of in the main .c source code file,
right? At any rate, I would greatly appreciate it if someone could
explain this to me.

thanks in advance,
Jared
Nov 14 '05 #1
3 5650
Jared <jg*****@tpg.co m.au> scribbled the following:
Hi, Can someone explain the basic structure of a header file? I just
completed a introductory C programming class. The course stressed
structured programming and creating reusable code. We learned to use
functions and to create our own. The problem is we never learned to
place them in header files. To me, and obviously, I'm not that
experienced with C, it would be better to place user created functions
in separate header files instead of in the main .c source code file,
right? At any rate, I would greatly appreciate it if someone could
explain this to me.


Header files should contain only prototypes of the user created
functions, not the function bodies themselves. That way you can
include the header file from multiple source files and not get any
linker errors.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Make money fast! Don't feed it!"
- Anon
Nov 14 '05 #2
Jared writes:
Can someone explain the basic structure of a header file? I just
completed a introductory C programming class. The course stressed
structured programming and creating reusable code. We learned to use
functions and to create our own. The problem is we never learned to
place them in header files. To me, and obviously, I'm not that
experienced with C, it would be better to place user created functions
in separate header files instead of in the main .c source code file,
right? At any rate, I would greatly appreciate it if someone could
explain this to me.


You didn't use quite the magic words. I think what you really want to know
about is separate compilation, which involves headers files and other things
(such as, perhaps, make files or "projects") as well. But that is a topic
related to the compiler, not the language, so is off-topic here. I suggest
doing a google advanced groups search to get your feet wet and then post a
question to a compiler oriented newsgroup. You *can*, indeed, put actual
code in a header file (it probably works) but it is bad practice in C. The
header itself simply contains function prototypes and stuff like that, the
actual *code* is in another .c file. In an introductory course you don't
even learn about the _linker_ which eventually ties all this assorted stuff
together.
Nov 14 '05 #3
Groovy hepcat Jared was jivin' on 12 Jan 2004 23:40:54 -0800 in
comp.lang.c.
custom header files's a cool scene! Dig it!
Can someone explain the basic structure of a header file? I just
Headers don't have any particular structure. They're just C source
files that are inserted into a translation unit at compile time. (A
translation unit is a C source file and all the headers it includes,
and, recursively, all the headers they include, compiled as one
logical unit.) Headers also define macros and data types needed by the
translation unit.
But headers are intended to declare functions and variables that may
be defined in other translation units. One or more compiled
translation units may be linked together to create a program.
Typically one compiled translation unit or a collection of them
comprises a library. A header usually declares the functions and
global data in the library and defines data types used by the library
and any macros that may be used to interface with the library. When
your program uses a library, you include its header in your code. This
tells your translation unit(s) how to interface with the library.
(Note that this applies not only to libraries, but also to programs
that have several translation units that are not a part of a library.)
completed a introductory C programming class. The course stressed
structured programming and creating reusable code. We learned to use
functions and to create our own. The problem is we never learned to
place them in header files. To me, and obviously, I'm not that


You don't put functions (definitions) in headers. You put function
*declarations* there, as well as type definitions, macro definitions
and variable declarations. You should never put executable code in a
header. You put the function and variable definitions that these
declarations refer to in a separate translation unit (if you desire -
and if you're concerned about reusable code, you ought to desire)
which also includes the header.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Nov 14 '05 #4

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

Similar topics

2
1520
by: 50295 | last post by:
Hi - I program in C++ but I'm not good with VC++ (yet). I will like to create a custom project for which a specific template or wizard does not exist. Because the program is a console application, I started out with the Win32 Console Project template. Having done that, the problem is that my application uses a custom header files and libraries (see code below) that VC++ does not know about. My question therefore is how do I
19
2510
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with the declaration for the C library function (stdlib.h in this case) then define/declare my own function with the same name, am I safe? It seems to work on my compiler, but I wonder if this is portable or even acceptable? thx
0
1260
by: Martial Artist | last post by:
Dear all, I have kinda general question, but as long as I will need ideas that to implement in C#, I will dare to ask. I have made a custom database file format to use in my application. The data is saved to the file using something like this : FileStream fs = new FileStream( this.path, FileMode.OpenOrCreate, FileAccess.ReadWrite ) ;
5
6858
by: Shelly | last post by:
hi, I am trying to create a custom HTTP header and trying to access that variable on another ASP.NET webpage. Following is the code base- I use the following code to set the header Response.AppendHeader("MYKEY", "myValue") and do a redirect to SecondPage.aspx
15
5759
by: joun | last post by:
Hi all, i want to create in my asp.net application a custom server variable, so i can retrieve later in other pages (even asp or perl) with request.servervariables("HTTP_mycustomvariable") i've tried with response.appendheader("mycustomvariable", "somevalue") but this doesn't work, or the variable scope is limited to aspx files, not asp or perl. So there is a solution with my problem, event with a external vc++ program?
0
3733
by: Dean Hallman | last post by:
Hello, I am developing a BHO that should add a custom HTTP header on a specific domain only. Don't want the header globally, otherwise I could just add a registry key. So, on BEFORENAVIGATE2, I am canceling the current navigation and renavigating with the new custom header using Navigate2. This usually works fine, but in some cases (particularly when selecting a link that starts a new window), the Navigate2 call fails.
5
5387
by: Ralph | last post by:
Hi Everyone, I need some help!! I'm not sure if you could do this, but I want to be able to create a report based on one field in the database. This field contains File Paths like for example: default.htm /en/example/aboutus.htm /fr/example/bonjour.htm /en/google/help/aboutus/findus.htm
0
1346
by: Andy Wynn | last post by:
Hello All, I've got a custom control ( Panel-like, but not inheriting from Panel) that has a header region that's custom drawn. Custom Control is using a custom controldesigner class that inherits from ParentControlDesigner. Just for starters I wanted to try to change the mouse cursor if it fell
4
2490
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.