Re: [PATCH] git-compat-util(msvc): C11 does not imply support for zero-sized arrays

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

 



"Johannes Schindelin via GitGitGadget" <gitgitgadget@xxxxxxxxx>
writes:

> diff --git a/git-compat-util.h b/git-compat-util.h
> index 19943e214ba..c9f508b3a83 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -46,7 +46,7 @@
>  /*
>   * See if our compiler is known to support flexible array members.
>   */
> -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && (!defined(__SUNPRO_C) || (__SUNPRO_C > 0x580))
> +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(_MSC_VER) && (!defined(__SUNPRO_C) || (__SUNPRO_C > 0x580))
>  # define FLEX_ARRAY /* empty */
>  #elif defined(__GNUC__)
>  # if (__GNUC__ >= 3)

Is flex array a requirement for STDC 199901L or newer?

I am assuming it is (e.g. https://en.wikipedia.org/wiki/C99), and I
can see that it is an unreliable source of information, given that
we see the second vendor whose conformance statement __STDC_VERSION__
makes contradicts with what the compiler does.

It might be that future MSC starts supporting flex array and this
line will become even harder to grok when it happens.  I'd rather
see us cleaning up the mess first.

Specifically, I am wondering if we should use the test based on
__STDC_VERSION__ as the last resort, giving the precedence to more
vendor specific tests, to avoid future problems.  That way, we can
cater to both camps of compiler vendors, the ones where their
STDC_VERSION may not say they have C99 but they do support flex
array the modern way, and the others where their STDC_VERSION say
they have C99 but the don't do flex array.

How about a preliminary clean-up patch that brings us to the
preimage of the following patchlet in step [1/2]?  Then we can do
the single-liner addition of _MSC_VER to support you, and the end
result would be a lot easier to read and maintain?

    /* Vendor specific exceptions first */
    #if   defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
   +#elif defined(_MSC_VER)
    #elif defined(__GNUC__)
    # if (__GNUC__ >= 3)
    #  define FLEX_ARRAY /* empty */
    # else
    #  define FLEX_ARRAY 0 /* older GNU extension */
    # endif
    #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
    # define FLEX_ARRAY /* empty */
    #endif

    /* Otherwise default to safer but wasteful */
    #ifndef FLEX_ARRAY
    # define FLEX_ARRAY 1
    #endif

Thanks.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux