clang++ cannot initialize a variable of type 'int(*)[dim2]' with an rvalue of type 'int (*)[dim2]'

前端 未结 3 1397
南笙
南笙 2021-01-27 12:31

Why does the code

void fcn(int *twoDArrayPtr, const int dim1, const int dim2) {
    int (*array)[dim2] = reinterpret_cast(twoDArrayPtr);
}

         


        
3条回答
  •  故里飘歌
    2021-01-27 12:59

    Although clang does not support variable-length arrays, there is a workaround. The following compiles with clang++ 4.0.0:

    void fcn(int *twoDArrayPtr, const int dim1, const int dim2) {
        using array_type = int (*)[dim2];
        array_type array = reinterpret_cast(twoDArrayPtr);
    }
    
    int main() {
        return 0;
    }
    

    I'm not sure why this alias declaration should make any difference. It certainly seems inconsistent.

提交回复
热议问题