Re: psql tab-complete

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Victor Spirin <v(dot)spirin(at)postgrespro(dot)ru>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: psql tab-complete
Date: 2022-12-21 22:41:08
Message-ID: CA+hUKGKLm8fdP_H3CtwgeMbe_6vqrKC20b+EtzTsmZOOVztCfg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Oct 26, 2019 at 4:59 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> On Fri, Oct 25, 2019 at 11:57:18AM +0300, Victor Spirin wrote:
> > This patch resolved one problem in the tab-complete.c on MSVC. The
> > VA_ARGS_NARGS macros now work correctly on Windows.
>
> Can you explain why and in what the use of EXPAND() helps with MSVC
> builds? Any references which help to understand why this is better?
> If this change is needed, this also surely needs a comment to explain
> the difference.

Since I really want to be able to use VA_ARGS_NARGS() elsewhere, I
looked into this. There are various derivatives of that macro, some
using GCC/Clang-only syntax and that work on GCC and MSVC, splattered
all over the internet, but the original, coming as it does from a C
standards newsgroup[1], does not. There are also lots of complaints
that the original standard version doesn't work on MSVC, with
analysis:

https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly
https://stackoverflow.com/questions/32399191/va-args-expansion-using-msvc
https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=msvc-170

The short version is that __VA_ARGS__ is not tokenized the way the
standard requires (it's considered to be a single token unless you
shove it back through the preprocessor again, which is what EXPAND()
does), but you can fix that with /Zc:preprocessor. That switch only
works in Visual Studio 2019 and up, and maybe also 2017 if you spell
it /experimental:preprocessor. We still claim to support older
compilers. Assuming those switches actually work as claimed, I see
two choices: commit this hack with a comment reminding us to clean it
up later, or drop 2015.

[1] https://groups.google.com/g/comp.std.c/c/d-6Mj5Lko_s

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-12-21 22:56:05 Re: psql tab-complete
Previous Message Andrew Dunstan 2022-12-21 22:01:30 Re: float4in_internal