我在 Embedded C 中多次使用类似于以下代码的代码。
#include <stdio.h>
int g_uArray[5] =
{ 1, 1, 2, 3, 5};
void* foo( int uIndex );
int main()
{
int* uVar;
uVar = foo( 2 );
printf( "Value = %u\n", *uVar );
return 0;
}
void* foo( int uIndex )
{
return (void*) &g_uArray[uIndex];
}
上面的代码在使用 gcc 编译时可以完美运行,但在使用 g++ 编译时会抛出错误
invalid conversion from ‘void*’ to ‘int*’
用于线
uVar = foo( 2 );
然而,它可以通过给出 -fpermissive 标志来编译。现在,我的问题是为什么 C++ 给出错误如此重要(gcc -Wall 甚至不给出警告)。如果我使用 -fpermissive 编译会产生一些运行时问题吗?