Comment

Comment by nkurz

I'm not familiar with MSVC, but when I tried this example:

  #include <stdio.h>

  void bar(int n, const char *p[]) {
    for (int i = 0; i < n; i++) {
      printf("%s\t", p[i]);
    }
    putchar('\n');
  }

  #define bar(...) (bar( \
  sizeof((const char*[]) { NULL, __VA_ARGS__ }) / sizeof(const char*) - 1, \
  (const char*[]) { NULL, __VA_ARGS__ } + 1))

  int main(/* int argc, char **argv */) {
    bar();
    bar("a");
    bar("a", "b");
    bar("a", "b", "c");
    return 0;
  }
Using the online MSVC compiler at http://webcompiler.cloudapp.net/ (which runs Visual C++ 19.00.23720.0), it failed with these error message:

  Compiled with  /EHsc /nologo /W4 /c
  main.cpp
  main.cpp(20): error C4576: a parenthesized type followed by    an 
  initializer list is a non-standard explicit type conversion syntax
  main.cpp(21): error C4576: a parenthesized type followed by an initializer
  list is a non-standard explicit type conversion syntax
  main.cpp(22): error C4576: a parenthesized type followed by an initializer list
  is a non-standard explicit type conversion syntax
  main.cpp(23): error C4576: a parenthesized type followed by an initializer list
  is a non-standard explicit type conversion syntax
parent nkurz 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton