警告 C4047:“int **"与“int[2][4]"的间接级别不同 [英] Warning C4047 : 'int **' differs in level of indirection from 'int[2][4]'

查看:139
本文介绍了警告 C4047:“int **"与“int[2][4]"的间接级别不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了这个警告,并且不知道为什么会这样.我在这里找到了许多解决 VS 2017 编译器中的警告的线程,但不是这个特定的组合:为什么 int** 与 int[X][Y] 的间接级别不同?

I'm getting this warning and scratching my head about why. I found many thread here that address this warning in VS 2017 compiler, but not this particular combination: why isn't int** the same level of indirection as int[X][Y]?

这是一个生成警告的精炼示例:

Here's a distilled down example that generates the warning:

void testfunc(int ** input, int ** output) {

  /*
  * Do something
  */

}


int main()
{


  int   firstvar[2][4];
  int   secondvar[2][4];

  testfunc(firstvar, secondvar);

}

我明白了:

testcode.c(46): 警告 C4047: 'function': 'int **' 与 'int [2][4]' 的间接级别不同

testcode.c(46): warning C4047: 'function': 'int **' differs in levels of indirection from 'int [2][4]'

任何关于为什么会这样或如何解决它的想法都非常感谢.

Any thoughts on why this would be or how to fix it much appreciated.

推荐答案

void testfunc(int input[][4], int output[][4])

会是一个更好的方式来传递这个.请注意 int ** 似乎表示它是一个 int * 数组,但它不是.

would be a better way to pass this. Please note int ** seems to indicate it is an array of int *, which it is not.

void onedimension_testfunc(int *odinput, int *odoutput)
{
     ...
}

int main ()
{
      int odfirst[4], odsecond[4];
      onedimention_testfunc(odfirst, odsecond);
}

在一个维度上,上面的代码工作正常.那是因为上面代码中的 odinput/odoutput 指向一个整数数组.但不适用于多个维度.

In one dimension the above code works fine. Thats because odinput/odoutput in the above code points to an integer array. But not for multiple dimensions.

这篇关于警告 C4047:“int **"与“int[2][4]"的间接级别不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆