From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 6 12:18:22 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9177116A4CE for ; Sat, 6 Mar 2004 12:18:22 -0800 (PST) Received: from kientzle.com (h-66-166-149-50.SNVACAID.covad.net [66.166.149.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 574F043D39 for ; Sat, 6 Mar 2004 12:18:22 -0800 (PST) (envelope-from tim@kientzle.com) Received: from kientzle.com (p54.kientzle.com [66.166.149.54]) by kientzle.com (8.12.9/8.12.9) with ESMTP id i26KIL90050422 for ; Sat, 6 Mar 2004 12:18:21 -0800 (PST) (envelope-from tim@kientzle.com) Message-ID: <404A320D.8090905@kientzle.com> Date: Sat, 06 Mar 2004 12:18:21 -0800 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.4) Gecko/20031006 X-Accept-Language: en-us, en MIME-Version: 1.0 To: hackers@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Style(9) and portability X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Mar 2004 20:18:22 -0000 One of the recommendations in style(9) is inherently non-portable. I'm trying to ensure that the new code I'm writing for FreeBSD is portable to other systems, so I've been scratching my head over how to deal with the version ID code that is supposed to apear as the first two lines of any FreeBSD source file: #include __FBSDID("$FreeBSD$"); Clearly, I cannot reasonably assume that all platforms define a __FBSDID macro in sys/cdefs.h. I'm looking for advice from people with a lot of experience on different Unix (and even non-Unix) systems to decide which of the following alternatives I should be using instead. The first option here will fail to port only if a system does not have a sys/cdefs.h header (or if it exists but provides a conflicting definition of __FBSDID, which seems highly unlikely): 1) #include #ifdef __FBSDID __FBSDID("$FreeBSD$"); #endif The second option deals with the issue by pushing it onto a header that encapsulates platform-specific definitions. In particular, the local platform.h header can include sys/cdefs.h on FreeBSD and provide an alternative definition of __FBSDID on other platforms. The drawback is, of course, the requirement for a new local header file to wrap platform-specific decisions: 2) #include "platform.h" /* Platform-specific defines */ __FBSDID("$FreeBSD$"); My instinct is that #1 is preferable in kernel source files and #2 is preferable in userland files, mostly from the belief that userland sources are more likely to be ported and therefore have more stringent portability concerns. Unless someone can suggest a better alternative, I'm probably going to implement some variation on #2 in libarchive and my other userland work going forward. Any input or advice appreciated, Tim Kientzle