Subject: __NetBSD_Version__ definition and ...
To: None <tech-misc@netbsd.org>
From: Alistair G. Crooks <agc@ftp.netbsd.org>
List: tech-misc
Date: 03/23/1999 06:48:55
Due to some things I had to do in pkgsrc the other day, I had cause
to use the __NetBSD_Version__ definition from <sys/param.h> for the
first time. Whilst I like the way we're now using the release, I
found it somewhat difficult to use. That got me thinking, and,
while I was having lunch today, came up with the following:

#define __NetBSD_Release__(a,b,c)       \
        ((((a) & 0xff) << 24) | (((b) & 0xff) << 16) | (c & 0xff))
#define __NetBSD_Current__(a,b,c)       \
        ((((a) & 0xff) << 24) | (((b) & 0xff) << 16) | ((((c) - 'A' + 1) & 0xff) << 8))

#define __NetBSD_Version__      0x01030b00 /* 1.3K */
/* this could just as easily be defined to be __NetBSD_Current__(1,3,'K') */

int
main()
{
        printf("release 1.3.1 is %08.8x\n", __NetBSD_Release__(1,3,1));
        printf("current 1.3K is %08.8x\n", __NetBSD_Current__(1,3,'K'));
        printf("__NetBSD_Version__ is %08.8x\n", __NetBSD_Version__);
#if __NetBSD_Version__ > __NetBSD_Release__(1,3,1)
        printf("> 1.3.1\n");
#endif
#if __NetBSD_Version__ < __NetBSD_Current__(1,3,'L')
        printf("< 1.3L\n");
#endif
	exit(0);
}

which produces the output:

release 1.3.1 is 01030001
current 1.3K is 01030b00
__NetBSD_Version__ is 01030b00
> 1.3.1
< 1.3L

In particular, I find it much easier to write __NetBSD_Current__(1,3,'K')
than having to work out 103110000 by hand, and similarly
__NetBSD_Release__(1,3,3) seems much more intuitive to me. We're
also good for 255 bumps of -current, too :-).

Comments?

Alistair