473,770 Members | 6,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about #ifndef fileName_h???

12 New Member
Hi, All
this is written in most of header files but i dont know its mean.The statements of file prototyp.h are
Expand|Select|Wrap|Line Numbers
  1. #ifndef PROTOTYP_H
  2. #define PROTOTYP_H
  3. ArrayAdd(LPARRAY,LPARRAY);
  4. ArraySubtract(LPARRAY,LPARRAY);
  5. #endif
  6.  
the upper bold words are. what is its purpose and where it is used
i have used #ifndef but in simple to check if any thing is not defined then run following code, but here with file name is new to me.
Thanks.
Jun 9 '09 #1
7 5450
Banfa
9,065 Recognized Expert Moderator Expert
Start here by reading about the C/C++ preprocessor directives.

In an include file it is common to use the preprocessor statements you have highlighted to prevent double inclusion of the file. The first time the file is included PROTOTYP_H is not defined and the code between the #ifndef and #endif is compiled, this includes defining PROTOTYP_H. That means that the second time the file is included PROTOTYP_H is defined so the code between the #ifndef and #endif is left out.

Preventing double inclusion is useful because declaring data structures (classes structures unions etc.) more than once produces a compiler diagnostic (an error message).
Jun 9 '09 #2
JosAH
11,448 Recognized Expert MVP
@plowgrammer2010
It's not a file name, it's a 'pp-token' which stands for 'pre-processor token'. If it isn't defined it is immediately defined at the next line and the entire content of the file is pre-processed; if it was defined before nothing is pre-processed.

It's a 'guard' mechanism that protects a file from multiple inclusion, i.e. if it was read before (the pp-token is defined) then the entire content of the file is skipped.

kind regards,

Jos

edit: too slow again, Banfa beat me again ;-)
Jun 9 '09 #3
plowgrammer2010
12 New Member
Thanks for your kind replies, it helped me a lot. i happy to join this forum. i will also use pp token for my next programming. here is another question.
I am micro-controller programmer for atmel 8051 in keil(ide and compiler).
My question is related to the topic.
When we include math.h in our standard c language or keil(microcontr oller's c), when we call any function like abs(12-50);
Only called function is included in our object or hex file. the object or hex file size is not so, big means there are so, many other functions in math.h they are not compiled and added in our hex, or object file.
But when i make my own header file put there 10 functions , and try to use one of them all are compiled and added in hex(i know because of size is large in compare without other 9 functions).
what is the method to adopt that technique
sorry for my English
Regards,
Jon.
Jun 9 '09 #4
Banfa
9,065 Recognized Expert Moderator Expert
I assume your implementation of the standard library is included as a lib. Typically the smallest unit a linker can add to a program is 1 object file.

A lib is normally a collection of object files but a well written standard library will have each function in a separate object file. It will do this by putting the source code for each function in the library in a separate source (c) file.

Probably what you have done is put all you functions into 1 c file producing 1 object file so that even if you only use 1 function the linker has to include the whole object and thus the code for all 10 functions making the program larger than needed.

Advanced linkers can remove unused functions from the final image, however most of these micro-processor compilers and linkers are not particularly advanced and so probably would not do this.

Try spliting your functions out into separate c files.
Jun 9 '09 #5
plowgrammer2010
12 New Member
There are for example 10 math functions, 20 string functions, 10 display functions, and so, on...
means i have to make 40 files, its ok for permenant library i will do. is there any method in our hands besides linker so, that include 1 file call function and related object file is included by the linker.
Jun 9 '09 #6
donbock
2,426 Recognized Expert Top Contributor
The compiler program translates a source file (.c) into an object file (.o). On unix the compiler program is typically called "cc".

The librarian program collects multiple object files (.o) and library files (.a) into a single library file (.a). On unix the librarian program is typically called "ar", for 'archiver'.

The linker program translates multiple object files (.o) and library files (.a) into a single executable file. On unix the linker program is typically also invoked by the "cc" command. Typically, the executable file produced by the linker includes all input object files in their entirety, but only the minimum number of object files from within the input library files needed to resolve all references.

If you know you want a set of object files to be present in your executable then you can just ask the linker to include those files -- no need to use the librarian. The purpose of the librarian is to provide the opportunity to minimize the size of the executable.
Jun 9 '09 #7
solita
17 New Member
it is to ensure that header file is included only once
Jun 11 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

17
6646
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products. So I shall have an Abstract Base called 'Car' implemented by Toyota, Ford, and Buick. Further I'd like to enable to client to say Car *factory;
5
8041
by: DrUg13 | last post by:
#ifndef HEADER_H #define HEADER_H blah blal #endif So this tells the compiler That if its defined do not define it again. Could someone help me understand this. Does this mean that if I use the same clasee in two different classes
6
1754
by: Johannes Bauer | last post by:
Hi group, I've got a question concerning inclusion of .hpp files. Currently I'm including all needed header files in the .cpp file. This means all dependencies of the package and all dependencies of these dependencies and so on. This is quite ugly. A start of an "Example.cpp" file could look like this
18
2257
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and the implementation of its member functions in foo.cpp (which obviously #inludes foo.h) and further assume that it depends on a class bar which is defined in bar.h. It seems that there are the following two scenarios:
1
1315
by: Tony Johansson | last post by:
Hello! Here I have one base klass and three subklasses. I Just want to have your opinion about the design of these klasses. I don't think that my design is good. I think that I instead should not have done the base class abstract it is so now but that is wrong I think. The base class should be concrete Define then method fetchWeaponName, fetchAllowedAnimal and getPrice in the
9
1795
by: John Smith | last post by:
I'm looking at some codes I wrote five years ago when taking a C++ course. Having not touched C++ since, I have forgotten most of it. Now I can't even comprehend my own codes. I have a question: What does these two lines in the attached header file do? I vaguely remember there is something special about the underscores. #ifndef __RECORD__
6
2040
by: AzizMandar | last post by:
There is probably a better way to do this and if so I'm just as happy to see that way. I have a program where I have factories that each create various objects abstracted from a base class. The Factories all have a base class as well for the objects to point back to. So I have
14
2153
by: JoeC | last post by:
I have been writing games and I also read about good programming techniques. I tend to create large objects that do lots of things. A good example I have is a unit object. The object controls and holds everything a unit in my game is supposed to do. What are some some cures for this kind of large object or are they OK because they represent one thing. If not what are better ways to design objects that behave the same way. Would it be...
4
1384
by: BSand0764 | last post by:
Apologies for the length of this message, but I'm having problems getting an alternate function to be executed via a functor implementation. I have two classes (BkgLand and BkgWater) that comprise a portion of a much larger simulation. These classes exist in separate libraries although the library that class BkgWater is in links in the library containing the BkgLand class (sounds confusing I know). In the simulation architecture that...
0
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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
5312
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
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
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
3573
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.