From: Jacek Caban Subject: Re: [PATCH 1/4] widl: Fix C++ RuntimeClass string constants declaration. Message-Id: Date: Fri, 26 Feb 2021 13:46:54 +0100 In-Reply-To: <20210226084306.2784145-1-rbernon@codeweavers.com> References: <20210226084306.2784145-1-rbernon@codeweavers.com> Hi Rémi, On 26.02.2021 09:43, Rémi Bernon wrote: > MinGW g++ requires initialized selectany to have extern linkage. > > When supported, we define WCHAR as char16_t, which requires u"" string > literal. When not supported, and when WCHAR is unsigned short, it then > requires to use an array initializer instead of a L"" string literal. > > Signed-off-by: Rémi Bernon > --- > tools/widl/header.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/tools/widl/header.c b/tools/widl/header.c > index a472af49066..23de3e12aca 100644 > --- a/tools/widl/header.c > +++ b/tools/widl/header.c > @@ -1836,8 +1836,18 @@ static void write_runtimeclass(FILE *header, type_t *runtimeclass) > fprintf(header, "#ifndef RUNTIMECLASS_%s_DEFINED\n", c_name); > fprintf(header, "#define RUNTIMECLASS_%s_DEFINED\n", c_name); > fprintf(header, "#if defined(_MSC_VER) || defined(__MINGW32__)\n"); > + fprintf(header, "#ifdef __cplusplus\n"); > + fprintf(header, "#if defined(WINE_UNICODE_NATIVE)\n"); > + fprintf(header, "extern const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = L\"%s\";\n", c_name, name); > + fprintf(header, "#else\n"); > + fprintf(header, "extern const DECLSPEC_SELECTANY WCHAR RuntimeClass_%s[] = {", c_name); > + for (i = 0, len = strlen(name); i < len; ++i) fprintf(header, "'%c',", name[i]); > + fprintf(header, "0};\n"); If we need the second case anyway, then I'm not sure if there is a point in the first one. I would expect the {...} initializer to produce the same result without having to worry about actual WCHAR type. With that, maybe we could reorder things a bit to simplify it. Would something like that work? #if !defined(__MINGW32__) && !defined(_MSC_VER) static const WCHAR RuntimeClass_...[] = {...}; #elif defined(__GNUC__) && !defined(__cplusplus) const DECLSPEC_SELECTANY WCHAR RuntimeClas_...[] = L"..."; #else extern const DECLSPEC_SELECTANY WCHAR RuntimeClas_...[] = {...}; #endif Thanks, Jacek