Maintainer checks for non-c89 constructs?

2007-06-09 Thread James Youngman

I maintain findutils on a GNU/Linux system using GCC.  Findutils uses
gnulib to provide a number of portability features, and also
extensions not in c89 such as bool.   With the help of gnulib, some
non-c89 things are available on c89-based systems.

However, gnulib cannot make the compiler look like a c99 compiler
because for example a c89 compiler would correctly reject this:

int
foo (void)
{
 int x = 2;
 printf (hello\n);
 int y = 3;   /* problem here */
 /* ... */
 return 0;
}

GCC accepts this construct because it is (or can be) a c99 compiler.
I find that about twice a year someone submits a bug report because
I've accidentally used a non-c89 construct without noticing.   Is
there any way I can use Automake to help me avoid this?

For example, is there any way to get make distcheck to try, where
possible, to compile in c89 mode if the compiler is GCC?   There are a
number of other flags and combinations which might be useful.

Thanks,
James.




Re: Maintainer checks for non-c89 constructs?

2007-06-09 Thread Ben Pfaff
James Youngman [EMAIL PROTECTED] writes:

 GCC accepts this construct because it is (or can be) a c99 compiler.
 I find that about twice a year someone submits a bug report because
 I've accidentally used a non-c89 construct without noticing.   Is
 there any way I can use Automake to help me avoid this?

For this particular problem, you can write an Autoconf test to
check whether the C compiler accepts
-Wdeclaration-after-statement and use it if so.

In GNU PSPP we do it this way:

dnl Check whether a C compiler option is accepted.
dnl If so, add it to CFLAGS.
dnl Example: PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)
AC_DEFUN([PSPP_ENABLE_OPTION],
[
  m4_define([pspp_cv_name], [pspp_cv_[]m4_translit([$1], [-], [_])])dnl
  AC_CACHE_CHECK([whether $CC accepts $1], [pspp_cv_name], 
[pspp_save_CFLAGS=$CFLAGS
 CFLAGS=$CFLAGS $1
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)], [pspp_cv_name[]=yes], 
[pspp_cv_name[]=no])
 CFLAGS=$pspp_save_CFLAGS])
  if test $pspp_cv_name = yes; then
CFLAGS=$CFLAGS $1
  fi
])

PSPP_ENABLE_OPTION(-Wdeclaration-after-statement)

-- 
Ben Pfaff
[EMAIL PROTECTED]