【问题标题】:Warning: passing argument x of 'foo' from incompatible pointer type警告:从不兼容的指针类型传递“foo”的参数 x
【发布时间】:2015-05-10 16:53:13
【问题描述】:

所以我在 AVR GCC 中编程,我已经查看了一些关于这个警告的类似问题,但我似乎无法找到一个明确的解决方案。

当使用多维数组中的数组作为函数的指针参数时,我收到此警告:

// Prototype
int getneighbours (uint8_t *neix[], uint8_t *neiy[], uint8_t nodex, uint8_t nodey);

// Call
uint8_t neighbours[2][4];
getneighbours (&neighbours[X], &neighbours[Y], nodex, nodey);

// Message
expected 'uint8_t **' but argument is of type 'uint8_t (*)[4]'

我之前一直很害怕在多维数组中使用指针,但我真的很想知道如何避免收到此警告?

问候

【问题讨论】:

    标签: pointers gcc gcc-warning


    【解决方案1】:

    我设法想出了解决我自己问题的方法:

    // Prototype
    void getneighbours (uint8_t (*nei)[2][4], uint8_t nodex, uint8_t nodey);
    
    // Call
    uint8_t neighbours[2][4];
    getneighbours (&neighbours, nodex, nodey);
    

    所以对于有同样问题的人来说,这就是你正确处理多维数组指针的方式。

    【讨论】:

      猜你喜欢
      • 2011-01-10
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      相关资源
      最近更新 更多