Content-Type: multipart/alternative; boundary="------------ux5VFnfICh8cYvOg0AotUPcQ" Message-ID: <861530ad-04c7-ced4-a88b-f71bdc11db0c@...68...> Date: Sat, 25 Mar 2023 00:02:49 +0100 MIME-Version: 1.0 Content-Language: en-US References: <20230323143140.76949-1-frank@...2641...> From: Matthias Andree In-Reply-To: Subject: Re: [Openvpn-devel] [PATCH] unit_tests: make cert_data.h compile with MSVC List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Selva Nair Cc: openvpn-devel@lists.sourceforge.net This is a multi-part message in MIME format. --------------ux5VFnfICh8cYvOg0AotUPcQ Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable Am 24.03.23 um 22:12 schrieb Selva Nair: > Hi, > > On Fri, Mar 24, 2023 at 4:18=E2=80=AFPM Matthias Andree > wrote: > > Am 23.03.23 um 15:31 schrieb Frank Lichtenheld: > > Currently this is not obvious since we never build the > > UTs with MSVC, but it doesn't like the initializers with > > "const" variables. They cause > > error C2099: initializer is not a constant > > What MSVC version are you using? What options? I've tried with a > minimal > C program with static const char *const foo =3D "something"; and it > compiled with the latest 2017 or 2022 MSVC. > > > That will work but the following wont: > > const char=C2=A0*const foo =3D "something"; > const char *const bar =3D foo; > > which is essentially the issue at hand. And more of the same with > struct initialization. As bar has static storage duration, it has to > be intialized by a "constant expression" which in C does not include > "const variables". Though it works with gcc.=C2=A0 In C99, automatic > variables can be intialized so, and the alternative I suggested uses > that approach. I must have missed that bar =3D foo part, which is indeed nonconforming code in C. With Microsoft tools, I always wonder if it's not easier in practice to make sure the same source code is also valid C++ and grind it in the C++ mixer^Wcompiler instead. --------------ux5VFnfICh8cYvOg0AotUPcQ Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Am 24.03.23 um 22:12 schrieb Selva Nair:
Hi,

On Fri, Mar 24, 2023 at 4:18=E2=80=AFPM Matthias Andree <matt= hias.andree@...68...> wrote:
Am 23.03.23 um 15:31 schrieb Frank Lichtenheld:
> Currently this is not obvious since we never build the
> UTs with MSVC, but it doesn't like the initializers with
> "const" variables. They cause
> error C2099: initializer is not a constant

What MSVC version are you using? What options? I've tried with a minimal
C program with static const char *const foo =3D "something"; and it
compiled with the latest 2017 or 2022 MSVC.

That will work but the following wont:

const char=C2=A0*const foo =3D "something";
const char *const bar =3D foo;

which is essentially the issue at hand. And more of the same with struct initialization. As bar has static storage duration, it has to be intialized by a "constant expression" which in C does not include "const variables". Though it works with gcc.=C2=A0 In C99, automatic variables can be intialized so, and the alternative I suggested uses that approach.


I must have missed that bar =3D foo part, which is indeed nonconforming code in C.

With Microsoft tools, I always wonder if it's not easier in practice to make sure the same source code is also valid C++ and grind it in the C++ mixer^Wcompiler instead.

--------------ux5VFnfICh8cYvOg0AotUPcQ--