代码之家  ›  专栏  ›  技术社区  ›  Prasoon Saurav

G++的VLA扩展在哪里?

  •  0
  • Prasoon Saurav  · 技术社区  · 14 年前

    我的问题与 this 线程。

    这是密码

    #include <stdio.h>
    
    int main(int argc, char *argv[printf("Hello, world!\n")]) {}
    

    我不小心把它保存为 *.cpp 文件并试图用 g++ . 但我得到了一个错误和警告。

    error: expected ',' or '...' before 'argv'
    warning: second argument of 'int main(int, char*)' should be 'char ** '

    我知道上面的代码不是标准的C++(数组的大小必须是C++中的常量表达式)。 我一直在想 G+ 支持可变长度数组作为扩展。我哪里错了?

    P.S:上面的代码是用clang编译的++

    C:\Users\SUPER USER\Desktop>type check.cpp
    #include <stdio.h>
    
    int main(int argc, char *argv[printf("Hello, world!\n")]) {}
    C:\Users\SUPER USER\Desktop>clang++ check.cpp
    
    C:\Users\SUPER USER\Desktop>
    
    1 回复  |  直到 14 年前
        1
  •  6
  •   Matthew Flaschen    14 年前

    G++允许(作为扩展)VLA。我认为它只是不允许它们出现在参数列表中。它在G++4.4.1中编译。

    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
        char *array[printf("Hello, world!\n")];
    }