[C2hs] Syntax error with __restrict symbol in regex.h

Will Thompson will at willthompson.co.uk
Sat Apr 1 10:18:40 EST 2006


Ahoy,

I am writing bindings for a library which includes regex.h from libc6
(version 2.6.3-3 in Debian). c2hs 0.14.5 refuses to parse regex.h as
follows:

    % c2hs Regex.chs
    c2hs: Error in C header file.

    /usr/include/regex.h:570: (column 125) [FATAL]
      >>> Syntax error!
      The symbol `restrict' does not fit here.

where Regex.chs contains:

    module Regex
    where
    #include <regex.h>

The offending section of regex.h is:

    /* GCC 2.95 and later have "__restrict"; C99 compilers have
       "restrict", and "configure" may have defined "restrict".  */
    #ifndef __restrict
    # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
    #  if defined restrict || 199901L <= __STDC_VERSION__
    #   define __restrict restrict
    #  else
    #   define __restrict
    #  endif
    # endif
    #endif
    /* gcc 3.1 and up support the [restrict] syntax.  */
    #ifndef __restrict_arr
    # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
    #  define __restrict_arr __restrict
    # else
    #  define __restrict_arr
    # endif
    #endif

    /* POSIX compatibility.  */
    extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
                                  const char *__restrict __pattern,
                                  int __cflags));

    extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
                                  const char *__restrict __string, size_t __nmatch,
                                  regmatch_t __pmatch[__restrict_arr],
                                  int __eflags));

which, according to c2hs -k, is transformed by cpp on my system to:

    # 566 "/usr/include/regex.h" 3 4
    extern int regcomp (regex_t *__restrict __preg, const char *__restrict __pattern, int __cflags);



    extern int regexec (const regex_t *__restrict __preg, const char *__restrict __string, size_t __nmatch, regmatch_t __pmatch[__restrict], int __eflags);

`c2hs --cppopts="-D__restrict=" ...` works around the problem, so this
is irritating rather than a showstopper. I spoke to Duncan about this on
IRC yesterday: this is still present with 0.14.5:

    % c2hs --version
    C->Haskell Compiler, version 0.14.5 Travelling Lightly, 12 Dec 2005
      build platform is "i686-pc-linux-gnu" <1, True, True, 1>

If I can provide any more information, let me know.

Will


More information about the C2hs mailing list