libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] 0.9.62 doesn't build on Visual Studio


From: Jonathan McDougall
Subject: Re: [libmicrohttpd] 0.9.62 doesn't build on Visual Studio
Date: Tue, 11 Dec 2018 20:04:03 -0500

On 12/11/18, Christian Grothoff <address@hidden> wrote:
> On 12/11/18 11:10 PM, Jonathan McDougall wrote:
>> Since you're willing to use C99 features, here's what I'm thinking
>> [...]
>
> This won't work. Sometimes we have two VLA variables, and with this
> you violate the c89 constraint that variables must be declared at the
> beginning of a code block

You're already using VLAs, which were introduced in C99 and made
optional in C11, so your code _already_ requires at least C99.

> Did you try mine with VS, or is your statement about this not being a
> 'constant' based on being picky about reading the standard?

Heh.

Visual Studio rejects your code, and clang as well as gcc in C89 mode
generate a warning, because they accept it as an extension. The C89
standard also says this is not a constant expression, see 6.4:

    Constant expressions shall not contain assignment,
    increment, decrement, function-call, or comma operators,
    except when they are contained within the operand of a
    sizeof operator.

Having anything else will only work if VLAs are available. In fact, even
something like (1, 2) as an array size will fail or warn, because it
contains a comma:


  $ cat a.c
  int main()
  {
      int a[(1, 2)];
  }

  $ gcc -std=C99 -pedantic a.c

  $ gcc -std=C89 -pedantic a.c
  a.c: In function ‘main’:
  a.c:3:5: warning: ISO C90 forbids variable length array ‘a’ [-Wvla]
       int a[(1, 2)];

  $ clang -std=c99 -pedantic a.c

  $ clang -std=c89 -pedantic a.c
  a.c:3:10: warning: variable length arrays are a C99 feature [-Wvla-extension]
      int a[(1, 2)];
         ^
  1 warning generated.

  > cl a.c
  Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27027.1 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.

  a.c
  a.c(3): error C2057: expected constant expression
  a.c(3): error C2466: cannot allocate an array of constant size 0
  a.c(3): error C2133: 'a': unknown size


> Because with my macro, the compiler _could_ certainly figure out that
> there is only one possible length of this array and generate the
> 'efficient' non-VLA logic.

Perhaps, but it would accepting an ill-formed program as per the
standard. All the compilers I've tested behave correctly in that regard,
by either rejecting the code or warning that it is an extension.

--
Jonathan McDougall



reply via email to

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