From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Bambach Subject: Re: #include problem Date: Fri, 15 Oct 2004 12:12:04 -0500 Sender: linux-c-programming-owner@vger.kernel.org Message-ID: <200410151212.04356.eric@cisu.net> References: <200410151648.i9FGmlqM026477@students.fct.unl.pt> <4170031D.4010309@bmind.it> Reply-To: eric@cisu.net Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4170031D.4010309@bmind.it> Content-Disposition: inline List-Id: Content-Type: text/plain; charset="us-ascii" To: pdovera Cc: linux-c-programming@vger.kernel.org On Friday 15 October 2004 12:04 pm, you wrote: > C-16 wrote: > >Howdy, > >i have a file main.c in my program that needs to include four headers > >aaa.h , bbb.h ,ccc.h and ddd.h . Each one of these headers need to > >include another header xxx.h . With this implementation i get a > >"redefinition" compilation error. How can i solve this problem ? Thanks > >in advance. >> > Hi, > If I understand well the redefinition problem is generated by xxx.h, so > you need to include xxx.h only once. > > into each file aaa.h, bbb.h, ccc.h, try the following code: > > #ifndef xxx_h > #include "xxx.h" > #endif > > so you will include xxx.h only once ! > xxx_h will not be included only the first time, the second time the > ifndef will be false (since xxx.h is already included) and so on ... This approach assumes he defines xxx_h in xxx.h. From the description I dont think he does. Anyways, this approach is backwards and the #ifndef business shouldn't be in each header file that needs xxx.h but rather in xxx.h itself. There have been many great replies to his problem that illustrate this. Imagine if he had 60-70 .cc/.h files needing xxx.h...... its impractical to maintain and write the #ifndefs in each file instead of writing it once in the xxx.h file. > Ciao, > Paolo Dovera > -- ---------------------------------------- EB > All is fine except that I can reliably "oops" it simply by trying to read > from /proc/apm (e.g. cat /proc/apm). > oops output and ksymoops-2.3.4 output is attached. > Is there anything else I can contribute? The latitude and longtitude of the bios writers current position, and a ballistic missile. --Alan Cox 2000-12-08 ----------------------------------------