Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preprocessor

Status
Not open for further replies.

spiderling66

Programmer
Aug 21, 2004
5
0
0
GB
anyone can help me, what does #define eg_H mean in the header file? and what action of preprocessor work on it?

the sections of code can be inserted by #include, but in the output of the preprocessor, does output contain these two /* prog.c */ and # include "eg.h" ?

the code is showing below:

/* eg.h */

#ifndef eg_H
#define eg_H

#define N 10
#define mymax(a,b) a > b ? a : b

# endif

-------------------------------------------

/* prog.c */
#include "eg.h"

main()
{
int a[N] ;
int maxa ;
int i ;

arrayInput (a , N);
maxa = a[0];
for ( i = 1; i < N; i++)
{
maxa = mymax ( maxa, a);
}
printf("maxa = %d\n", maxa);
}

thanks

 
> what does #define eg_H mean in the header file?
It allows you to include the same file twice without generating lots of "redefined" errors.

The first time you include the file, eg_H will not be defined (so #ifndef will be true), and the rest of the file will be included.

If you then try and include the same file again, eg_H will be defined (so #ifndef will be false), and the body of the file will be skipped.

In simple programs, avoiding including the same file twice is easy to do, but in large projects containing hundreds or thousands of source files, it's much harder to do.

--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top