[Top][All Lists]

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

Detection of ISO C89 compiler

From: Patrick Pelissier
Subject: Detection of ISO C89 compiler
Date: Fri, 19 Nov 2010 12:49:51 +0100


 I have a question about the detection of an ISO C89 compliant
compiler by autoconf.
 With autoconf 2.68 (and some older version), it uses the following C code
 (from the macro _AC_PROG_CC_C89 in lib/autoconf/c.m4).

/* end confdefs.h.  */
#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
     char **p;
     int i;
  return p[i];
static char *f (char * (*g) (char **, int), char **p, ...)
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not '\xHH' hex character constants.
   These don't provoke an error unfortunately, instead are silently treated
   as 'x'.  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
   array size at least.  It's necessary to write '\x00'==0 to get something
   that's true only with -std.  */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *,
int), int, int);
int argc;
char **argv;
main ()
return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
  return 0;

 I do not understand why you include sys/types.h and sys/stat.h.
 I think that these header files are not mandatory for an ISO C89 compiler.

 My problem was when I try to cross-compile a package with a cross-compiler
 without these headers. The test fails and the compiler is assumed to be
 a K&R compiler, and as such ansi2knr is used.
 The final problem is that ansi2knr assumes a K&R compiler without
 malloc and free, and defines its own prototype of malloc and free
 which are not compatible in stdlib.h. From ansi2knr:
     extern char *malloc();                     extern int free();
 From stdlib.h
     extern void *malloc(size_t size);      extern void free(void *ptr);
 So I get a conflicting prototype error...
 I resolved my problem by skipping the test:
   ./configure ac_cv_prog_cc_c89= [...]

 But I still wonder why the test detecting an ISO C89 compiler
 uses sys/types.h and sys/stat.h.

  Patrick PĂ©lissier

reply via email to

[Prev in Thread] Current Thread [Next in Thread]