NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: NetBSD macros



Masao Uebayashi wrote:
> > There is not much else you can do apart from writing code like:
> > 
> > #if NetBSD && NetBSD_Version >= 5.0
> >     use NetBSD atomic_ops
> > #elif Solaris
> >     use Solaris atomic_ops
> > #elif Linux
> >     use Linux atomic_ops
> > #else
> >     use pthread_mutex_lock
> > #endif
> 
> How many kind of interfaces do you need?  If you're not going to write a
> software which can run on top of either GNOME or KDE or whatever, you
> won't need autoconf

The number of #if tests isn't governed by the number of interfaces.  The
above code expands with the number of operating systems.  Where are the
other BSDs, the 2.4 linux kernel, Irix, AIX, etc?  And how do you know
where to put them?  

By letting autoconf test for functionality, which matters, rather than OS,
which doesn't, the code becomes more robust, more portable, and more
readable:

#if _HAVE_ATOMIC_OPS_1
        use NetBSD atomic_ops
#elif _HAVE_ATOMIC_OPS_2
        use Solaris atomic_ops
#elif _HAVE_ATOMIC_OPS_3
        use Linux atomic_ops
#elif _HAVE_ATOMIC_OPS_4
        use pthread_mutex_lock
#else
#error "need some kinda atomic ops"
#endif

(Of course, the _HAVE_ label could be more descriptive.) 

--jkl


Home | Main Index | Thread Index | Old Index