如何解决如何访问另一个指针内部的结构内部的元素作为指针?
| 我正在尝试将SuperLU用于矩阵求逆,但无法访问最终结果。它为反转使用了一些结构,我知道答案在结构内部,但我无法引用它。 B被定义为具有以下格式的超级矩阵:typedef struct {
Stype_t Stype; /* Storage type: indicates the storage format of *Store. */
Dtype_t Dtype; /* Data type. */
Mtype_t Mtype; /* Mathematical type */
int nrow; /* number of rows */
int ncol; /* number of columns */
void *Store; /* pointer to the actual storage of the matrix */
} SuperMatrix;
根据Stype,商店的结构会发生变化。对于B,用于* Store的结构为:
typedef struct {
int lda; /* leading dimension */
void *nzval; /* array of size lda-by-ncol to represent
a dense matrix */
} DNformat;
因此,B的最终结构应为:
B = { Stype = SLU_NC; Dtype = SLU_D; Mtype = SLU_GE; nrow = 5; ncol = 5;
*Store = { lda = 12;
nzval = [ 19.00,12.00,21.00,16.00,5.00,18.00 ];
}
}
现在我想从nzval中复制值,但是我不确定该怎么做。
我尝试做B.Store.nzval,但是错误是\“请求成员“ nzval \”在某种非结构或联合体中”
也
DNformat **g = B.Store;
int *r = *(g->nzval);
以及其他一些类似的事情,但不确定如何解决。
非常感谢!
解决方法
DNformat *g = (DNformat *)B.store;
int *r = (int *)g->nzval;
如果要简洁,可以将它们放在一起:
int *r = (int *)((DNformat *)B.store)->nzval;
, 这是因为Store是结构中的指针。 DNFormat也声明为void *;这意味着Store是一个空指针,没有强制转换就无法取消引用;而且它是一个指针这一事实意味着您必须使用解引用运算符->
((DNFormat *)B.Store)->nzval
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。