473,396 Members | 1,852 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,396 software developers and data experts.

Question about #ifndef fileName_h???

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 5425
Banfa
9,065 Expert Mod 8TB
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 Expert 8TB
@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
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(microcontroller'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 Expert Mod 8TB
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
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 Expert 2GB
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
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
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....
5
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...
6
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...
18
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...
1
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 ...
9
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:...
6
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. ...
14
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...
4
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.