gpt4 book ai didi

c - 调用 CLAPACK 函数后变量初始化

转载 作者:太空宇宙 更新时间:2023-11-04 04:48:29 25 4
gpt4 key购买 nike

我最近设法构建并运行了一个简单的 CLAPACK Microsoft Visual Studio 2008 项目(从 http://icl.cs.utk.edu/lapack-for-windows/lapack/index.html 下载)。之后,在 LAPACK dgesv_ 调用后插入一行以初始化另一个整数 tempInteger 会导致构建失败。错误是:CLAPACK-EXAMPLE.c(30):错误 C2143:语法错误:缺少“;”在“类型”之前。看起来 LAPACK 函数的执行阻止了某些操作,例如之后的变量初始化。谁能帮我了解发生了什么并解决它?提前致谢。代码 list 如下:

#include < stdio.h>
#include "f2c.h"
#include "clapack.h"

int main(void)
{
/* 3x3 matrix A
* 76 25 11
* 27 89 51
* 18 60 32
*/
double A[9] = {76, 27, 18, 25, 89, 60, 11, 51, 32};
double b[3] = {10, 7, 43};

int N = 3;
int nrhs = 1;
int lda = 3;
int ipiv[3];
int ldb = 3;
int info;
int qqq = 1;

dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);

if(info == 0) /* succeed */
printf("The solution is %lf %lf %lf\n", b[0], b[1], b[2]);
else
fprintf(stderr, "dgesv_ fails %d\n", info);

int tempInteger = 1;

return info;
}

最佳答案

如果此文件编译为 C 文件而不是 C++ 文件,则应在函数顶部声明 tempInteger 类型。例如:

#include < stdio.h>
#include "f2c.h"
#include "clapack.h"

int main(void)
{
/* 3x3 matrix A
* 76 25 11
* 27 89 51
* 18 60 32
*/
double A[9] = {76, 27, 18, 25, 89, 60, 11, 51, 32};
double b[3] = {10, 7, 43};

int N = 3;
int nrhs = 1;
int lda = 3;
int ipiv[3];
int ldb = 3;
int info;
int qqq = 1;
int tempInteger;

dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);

if(info == 0) /* succeed */
printf("The solution is %lf %lf %lf\n", b[0], b[1], b[2]);
else
fprintf(stderr, "dgesv_ fails %d\n", info);

tempInteger = 1;

return info;
}

关于c - 调用 CLAPACK 函数后变量初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18396025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com