[prog] Solution
Mary
mary-linuxchix at puzzling.org
Sat Feb 1 13:11:47 EST 2003
On Sat, Feb 01, 2003, Jenn Vesperman wrote:
> I can't see a need to have separate header files for each set of
> #included code, nor to surround the #included code in #ifdefs. C will
> only link the headers once, it should be fine to multiply include them
> if you do wind up doing so.
Really? In the following situation:
A.h:
#define A
typedef int a;
B.h
#include "A.h"
#define B
C.h
#include "A.h"
#define C
A.c
#include "B.h"
#include "C.h"
where A.c is including A.h through two different header files, I get the
following error:
In file included from C.h:1,
from A.c:2:
A.h:3: redefinition of `a'
A.h:3: `a' previously declared here
Hence, major system libraries all use ifndefs to protect from multiple
inclusion, for example, /usr/include/stdio.h on my system begins:
#ifndef _STDIO_H
# define _STDIO_H 1
.
.
.
It's fine to multply include function definitions I believe (as long as
they have the same signature) but definitions will cause an error.
-Mary
More information about the Programming
mailing list