From owner-freebsd-hackers Mon Mar 4 5:11:43 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mail5.nc.rr.com (fe5.southeast.rr.com [24.93.67.52]) by hub.freebsd.org (Postfix) with ESMTP id 6B3A737B417; Mon, 4 Mar 2002 05:11:35 -0800 (PST) Received: from i8k.babbleon.org ([66.57.85.154]) by mail5.nc.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Mon, 4 Mar 2002 08:11:34 -0500 Received: by i8k.babbleon.org (Postfix, from userid 111) id 9A2CDBA03; Mon, 4 Mar 2002 08:06:08 -0500 (EST) Content-Type: text/plain; charset="iso-8859-1" From: Brian T.Schellenberger To: Aleksander Rozman - Andy , freebsd-hackers@FreeBSD.ORG Subject: Re: How to write code in FreeBSD Date: Mon, 4 Mar 2002 08:06:08 -0500 X-Mailer: KMail [version 1.3] Cc: freebsd-questions@FreeBSD.ORG References: <5.0.2.1.0.20020302125303.02c1ca90@164.8.8.5> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20020304130608.9A2CDBA03@i8k.babbleon.org> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Saturday 02 March 2002 09:41 am, Brian T. Schellenberger wrote: > On Saturday 02 March 2002 06:57 am, Aleksander Rozman - Andy wrote: > > Hi ! > > > > I was wondering if there are any guidelines how to write code in FreeBSD. > > I have taken a look at several code of FreeBSD but each is written > > differently? Problem is I don't know which is preferred way. > > > > Reason I am asking this is that I am trying to add some code to kernel. > > Compile is OK, no error, no warning, but on link all variables defined > > with extern are marked as : undefined reference to 'variable', variable > > is extern and .h file which has it defined is included... Where can be > > the problem?? Another problem is that I get multiple definition > > error...how can I get over this. I got Andy to send his original code, and I believe that I've diagnosed the root of the problem: The code was assuming that KERNEL was defined when building the kernel (I gather that KERNEL is defined when building a Linux kernel), but under FreeBSD, it seems, KERNEL is *not* defined, but _KERNEL is defined instead. (Though I'm not sure whether it's defined under the same circumstances.) Even so I'm not sure that his code is perfectly correct ANSI C, technically speaking, since it then appears that it would wind up with multiple copies of the variables defined, but I'm pretty darn sure that gcc & ld tolerate this just fine--the proximate cause of the difficulty lay in expecting KERNEL to be defined and having an #ifdef KERNEL check in the 'h' file that caused the definitions to never to be read. -- Brian T. Schellenberger . . . . . . . bts@wnt.sas.com (work) Brian, the man from Babble-On . . . . bts@babbleon.org (personal) ME --> http://www.babbleon.org http://www.eff.org <-- GOOD GUYS --> http://www.programming-freedom.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message