Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 06 Mar 2004 12:18:21 -0800
From:      Tim Kientzle <tim@kientzle.com>
To:        hackers@freebsd.org
Subject:   Style(9) and portability
Message-ID:  <404A320D.8090905@kientzle.com>

next in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h>
__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 <sys/cdefs.h>
     #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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?404A320D.8090905>