g ++的VLA扩展在哪里? [英] Where's g++'s VLA extension?
问题描述
我的问题与此主题相关。
以下是代码
: #include< stdio.h> ;
int main(int argc,char * argv [printf(Hello,world!\\\
)]){}
我不小心将其保存为 *。cpp
文件,并尝试使用 g ++
。但我收到了错误和警告。
错误:预期','或'...' 'argv'
警告:'int main(int,char *)'的第二个参数应为'char **
' / code>
我知道上面的代码不是标准C ++ [数组大小必须是C ++中的常量表达式]但
我一直认为 g ++
支持可变长度数组作为扩展。我错了?
PS:上面的代码用CLang ++编译
C:\Users\SUPER USER\Desktop> type check.cpp
p> g ++允许(再次作为扩展)VLA。我认为它只是不允许他们在参数列表。这在g ++ 4.4.1中编译。
#include< stdio.h>
int main(int argc,char * argv [printf(Hello,world!\\\
)]){}
C:\Users\SUPER USER\Desktop> ; clang ++ check.cpp
C:\Users\SUPER USER\Desktop>
#include< stdio.h>
int main(int argc,char * argv [])
{
char * array [printf(Hello,world!\\\
)];
}
My question is related to this thread.
Here is the code
#include <stdio.h> int main(int argc, char *argv[printf("Hello, world!\n")]) {}
I accidently saved it as a
*.cpp
file and tried to compile it withg++
. But I got an error and a warning.
error: expected ',' or '...' before 'argv'
warning: second argument of 'int main(int, char*)' should be 'char ** '
I know the above code is not Standard C++ [size of an array must be a constant expression in C++] but I always thought
g++
supports Varible Length Array as an extension. Where am I wrong?P.S : The above code gets compiled with 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>
解决方案g++ allows (again, as an extension) VLAs. I think it just doesn't allow them in parameter lists. This compiles in g++ 4.4.1.
#include <stdio.h> int main(int argc, char *argv[]) { char *array[printf("Hello, world!\n")]; }
这篇关于g ++的VLA扩展在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!