MSVC中C99向多维数组的转换

MSVC中C99向多维数组的转换,c,multidimensional-array,visual-studio-2015,c99,dynamic-memory-allocation,C,Multidimensional Array,Visual Studio 2015,C99,Dynamic Memory Allocation,考虑以下矩阵声明: typedef struct { uint32_t rows; uint32_t cols; uint8_t *data; } matrix8; // A function to allocate above matrix. matrix8 * matrix8_alloc(uint32_t rows, uint32_t cols); 我使用以下宏使访问矩阵中的[x][y]位置更容易: #define GET_M8(m) ((uint8_t (

考虑以下矩阵声明:

typedef struct {
    uint32_t rows;
    uint32_t cols;
    uint8_t *data;
} matrix8;

// A function to allocate above matrix.
matrix8 * matrix8_alloc(uint32_t rows, uint32_t cols);
我使用以下宏使访问矩阵中的
[x][y]
位置更容易:

#define GET_M8(m)    ((uint8_t (*)[m->cols])m->data)

matrix8 *m = matrix8_alloc(100, 100);
uint8_t val = GET_M8(m)[x][y];
在使用gcc和clang编译时,这种方法工作得很好。它似乎也是兼容C99的(这种用法的最初想法来自于)

但是,当使用MSVC(cl.exe v19.00.23506)进行编译时,我得到了与该宏相关的以下错误:

error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2036: 'uint8_t (*)[0]': unknown size

问题是,MSVC在这方面缺乏支持吗?以上是CAST便携式软件吗?< /P>是的,微软在C语言的基础上,一般只实现C++的C特征,我自己对这个主题的研究也得出了类似的结论。是的,微软通常只在C89的时候才实现C++以外的C特征。我自己对这个主题的研究也得出了类似的结论。请随意将此作为答案发布。