Header files?

Another questions.

With regards to header files?

Lets say I have a header file 'add.h' .

Can it contain multiple includes all in the same file. eg below.

in add.h
----------------

#ifndef ADD_H
#define ADD_H
void add(int a, int b);
#endif

#ifndef ADD1_H
#define ADD1_H
void add1(int a, int b);
#endif

#ifndef ADD2_H
#define ADD2_H
void add2(int a, int b);
#endif

#ifndef ADD3_H
#define ADD3_H
void add3(int a, int b);
#endif

Thanks
Last edited on
Is your question if you can have more than one function declaration in a header file? If that's your question the answer is yes, but there is no need to use multiple header guards.
1
2
3
4
5
6
7
#ifndef ADD_H
#define ADD_H
void add(int a, int b);
void add1(int a, int b);
void add2(int a, int b);
void add3(int a, int b);
#endif 


Strictly speaking you don't need a header guard at all in this case.
Thanks. That was the question and yes your answer answers it perfectly.
so I'm assuming ADD_H is supposed to be aligned with the file name add.h.

Is that correct.
http://stackoverflow.com/questions/1653958/why-are-ifndef-and-define-used-in-c-header-files

http://en.wikipedia.org/wiki/Include_guard

... and others, google
#ifndef header


---

ps.> if you read the above and study preprocessor directives carefully, you should understand that "ifndef" in your add.h does not necessarily need to meet the header file name. #ifndef FOO123_YEP wil serve just as good as far as some foo maniac have not defined FOO123_YEP somewhere else :)
Last edited on
In fact, you should find an unused define.
Reason why you should try to have the file name inside the define.

Examples:
FOO_H_INCGUARD
FOO_H_DEF
FOO_HEADER
> http://stackoverflow.com/questions/1653958/why-are-ifndef-and-define-used-in-c-header-files
> That prevent double declaration of any identifiers such as types, enums and static variables.
which is not the case here, as you only have function declarations.
Topic archived. No new replies allowed.