We've recently stopped pretending to support building slapd with a K&R C compiler; it makes some sense to apply that to the libraries as well. They are designed to be build-able in more places but it makes sense to require at least an ANSI C, considering the amount header cleanup we could do.
I'm also interested in potentially requiring some ISO C99 features; in particular variadic macros are very very attractive. In addition to simplifying internal macro design, it allows for a great deal of cleanup and more flexibile macro use in the rest of OpenLDAP.
Consider Debug() and Statslog(); currently they are mostly the same, with the idea that Statslog takes two extra dedicated args (for connid and opid), and that Statslog() should appear even in a non- LDAP_DEBUG build. As it sits, they don't share code and are implemented separately. Worse, we have lots of
Debug( LDAP_DEBUG_FOO, "foo\n", 0, 0, 0 );
Where the 0's should not be necessary. Consider the case of adding a new compile-optional logging type; one currently needs to extend the macros for Debug() and Statslog() separately, and maintain large and separate ifdef trees for each build-option permutation. A more elegant solution involves using a set of common macros to implement Debug and Statslog internally, but without variadic macros there must be separate implementations for each argument count, which defeats the purpose of unifying them in the first place.
Or we could preprocess all of the .c with m4...
But really, it seems reasonable to borrow a few features from a standard from 1999. Is anyone actively maintaining OpenLDAP on platforms with no C99ish compiler available?
Matthew Backes Symas Corporation mbackes@symas.com
Matthew Backes mbackes@symas.com writes:
But really, it seems reasonable to borrow a few features from a standard from 1999. Is anyone actively maintaining OpenLDAP on platforms with no C99ish compiler available?
If you support both the C99 varient and the old gcc varient, I expect you cover everything anyone might care about. People with old platforms can use gcc instead.
Here is the Autoconf probe that I use to detect variadic macro support.
dnl vamacros.m4 -- Check for support for variadic macros. dnl $Id: vamacros.m4 6544 2003-12-26 03:23:31Z rra $ dnl dnl This file defines two macros for probing for compiler support for variadic dnl macros. Provided are INN_C_C99_VAMACROS, which checks for support for the dnl C99 variadic macro syntax, namely: dnl dnl #define macro(...) fprintf(stderr, __VA_ARGS__) dnl dnl and INN_C_GNU_VAMACROS, which checks for support for the older GNU dnl variadic macro syntax, namely: dnl dnl #define macro(args...) fprintf(stderr, args) dnl dnl They set HAVE_C99_VAMACROS or HAVE_GNU_VAMACROS as appropriate.
AC_DEFUN([INN_C_C99_VAMACROS], [AC_CACHE_CHECK([for C99 variadic macros], [inn_cv_c_c99_vamacros], [AC_TRY_COMPILE( [#include <stdio.h> #define error(...) fprintf(stderr, __VA_ARGS__)], [error("foo"); error("foo %d", 0); return 0;], [inn_cv_c_c99_vamacros=yes], [inn_cv_c_c99_vamacros=no])]) if test $inn_cv_c_c99_vamacros = yes ; then AC_DEFINE([HAVE_C99_VAMACROS], 1, [Define if the compiler supports C99 variadic macros.]) fi])
AC_DEFUN([INN_C_GNU_VAMACROS], [AC_CACHE_CHECK([for GNU-style variadic macros], [inn_cv_c_gnu_vamacros], [AC_TRY_COMPILE( [#include <stdio.h> #define error(args...) fprintf(stderr, args)], [error("foo"); error("foo %d", 0); return 0;], [inn_cv_c_gnu_vamacros=yes], [inn_cv_c_gnu_vamacros=no])]) if test $inn_cv_c_gnu_vamacros = yes ; then AC_DEFINE([HAVE_GNU_VAMACROS], 1, [Define if the compiler supports GNU-style variadic macros.]) fi])
On Jan 17, 2008, at 2:53 PM, Russ Allbery wrote:
If you support both the C99 varient and the old gcc varient, I expect you cover everything anyone might care about.
Not.
People with old platforms can use gcc instead.
This issue is not restricted to old platforms. It is relatively common to want to build software using the compiler provided by the platform vendor, whether that platform/compiler is new or old. There are very new platforms/compilers that don't support various C99 features.
-- Kurt
On Jan 16, 2008, at 10:20 PM, Matthew Backes wrote:
We've recently stopped pretending to support building slapd with a K&R C compiler;
For years now, the Project has required ANSI C (C90) to build OpenLDAP Software (e.g., slapd(8)) but published headers for public interfaces that worked with either K&R C or ANSI C (any revision).
The Project has avoided is requiring later versions of ANSI C to build OpenLDAP Software as support for those features is not ubiquitous. Some ANSI C compilers still cannot handle inline functions (use macros instead), unrestricted variable declarations (declare variables at top of block), // comments (use /* */ comments), etc.
Debug( LDAP_DEBUG_FOO, "foo\n", 0, 0, 0 );
Support for variadic macros is not terribly ubiquitous.
But really, it seems reasonable to borrow a few features from a standard from 1999. Is anyone actively maintaining OpenLDAP on platforms with no C99ish compiler available?
Yes.
-- Kurt