Style(9) and portability
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 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Style(9) and portability
At 20:18 06/03/2004, Tim Kientzle wrote: 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. Portability doesn't mean the code wiil compile on every platform and C compiler in the world. Most platforms will have their own packaging systems and directory hierarchy, so *some* changes will have to be made every time code is ported; as long as the necessary changes are obvious, I don't see that there is any real problem. Colin Percival ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Style(9) and portability
At 12:18 PM -0800 3/6/04, Tim Kientzle wrote: ... 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. Really, you can't even assume that all platforms will *have* a sys/cdefs.h 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$); This is basically the tactic that I went with for everything under lpr. That works reasonably well for lpr, but I don't know if it makes sense for everything: #include lp.cdefs.h /* A cross-platform version of sys/cdefs.h */ I intentionally have the comment about sys/defs.h, in case someone comes along later and scans for that string... -- Garance Alistair Drosehn= [EMAIL PROTECTED] Senior Systems Programmer or [EMAIL PROTECTED] Rensselaer Polytechnic Instituteor [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Style(9) and portability
On Sat, Mar 06, 2004 at 12:18:21PM -0800, Tim Kientzle wrote: 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. Our compiler defines __FreeBSD__. You might be able to do: #ifdef __FreeBSD__ #include sys/cdefs.h __FBSDID($FreeBSD$); #endif The advantage of something like this is that you don't spam the library on non-FreeBSD systems. Just a thought... -- Marcel Moolenaar USPA: A-39004 [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]