简体   繁体   English

指针类型不兼容?? 奇怪的

[英]Incompatible pointer type?? Strange

I need to get the solution of an equation system.我需要得到方程组的解。 For this purpose i use the function sgesv_().为此,我使用 function sgesv_()。

Everything works great, and it retur me the right results of the solution.一切都很好,它返回了解决方案的正确结果。

But i get an strange Warning.但我收到一个奇怪的警告。

warning: passing argument 3 of 'sgesv_' from incompatible pointer type警告:从不兼容的指针类型传递“sgesv_”的参数 3

I am using the function as Apple use it on the WWDC video.我正在使用 function,因为 Apple 在 WWDC 视频中使用它。

What am I doing wrong?我究竟做错了什么?

a1,a2,b1,b2,c1,c2 are floats a1,a2,b1,b2,c1,c2 是浮点数

        __CLPK_integer info;
        __CLPK_integer n=2;
        __CLPK_integer nb=1;
        __CLPK_integer ipiv[n];
        float A[n][n];
        A[0][0]=a1;
        A[0][1]=a2;
        A[1][0]=b1;
        A[1][1]=b2;
        float B[n];
        B[0]=-c1;
        B[1]=-c2;
        sgesv_(&n, &nb, A, &n, ipiv, B, &n, &info);

The third parameter is meant to be a float * but you're passing a 2D array of float.第三个参数是一个float * ,但您传递的是一个二维浮点数组。 It just so happens that these floats are in the right order.碰巧这些花车的顺序是正确的。 To get rid of the warning you can do this:要摆脱警告,您可以这样做:

    sgesv_(&n, &nb, &A[0][0], &n, ipiv, B, &n, &info);

or this:或这个:

    sgesv_(&n, &nb, A[0], &n, ipiv, B, &n, &info);

or even this:甚至这个:

    sgesv_(&n, &nb, (float *)A, &n, ipiv, B, &n, &info);

Or you could just "flatten" your A array, eg或者您可以“展平”您的 A 阵列,例如

    float A[n * n];
    A[0 * n + 0] = a1;
    A[0 * n + 1] = a2;
    A[1 * n + 0] = b1;
    A[1 * n + 1] = b2;
    // ...
    sgesv_(&n, &nb, A, &n, ipiv, B, &n, &info);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM