hercules-390 / hyperion

Hercules 390
Other
246 stars 69 forks source link

C99 Flexible array support disabled when compiling on clang. #222

Open srorso opened 7 years ago

srorso commented 7 years ago

When building Hercules on a system using clang 3.8, C99 flexible array support is disabled even though clang supports flexible arrays. See Intentionally Unsupported GCC Extensions for details; the lead bullet disclaims support for variable length arrays but does state that flexible arrays are supported.

Macro: HC_C99_FLEXIBLE_ARRAYS() in autoconf/hercules.m4 tests for C99 flexible arrays by providing headers and a main() to AC_TRY_LINK. Unforturnately, the resulting main() function looks like this:

int
main()
{
    int main(int argc, char *argv[])
    {
            FOOBAR* p = calloc( 1, sizeof(FOOBAR) + 16 );
            return 0;
    }
return 0;
}

The gcc compiler treats this as a supported nested function definition and generates a few warnings. The test is passed because autotools does not treat warnings as errors by default, and C99 flexible array support is included.

The clang compiler does not support nested function definitions (see the second bullet here), errors out on the compile, and C99 flexible array support is not included.

Paring down the AC_TRY_LINK program body to just this statement:

            FOOBAR* p = calloc( 1, sizeof(FOOBAR) + 16 );

addresses the issue. Clean build, make check passes on FreeBSD 11.

I will address this in the autotools build if there is significant interest.

ghost commented 7 years ago

I will address this in the autotools build if there is significant interest.

things work, so it is not strictly necessary, but good coding habits ask it to be fixed

just get rid of the RYO junk and take a look at the macros

AC_C_FLEXIBLE_ARRAY_MEMBER, AC_C_VARARRAYS

cheers e