我有一个单元测试程序,用于在初始编译之前捕获开源项目功能中的错误。我需要测试的所有函数都返回一个指向结构的指针(在这种情况下bn_poly
),而我的变量不是指针。我知道这个问题必须有一个更简单的解决方案,但是经过一番谷歌搜索后我什么也没想到,这就是我目前正在做的事情
/* only relevant part of code */
struct *bn_poly poly_summ;
unsigned i
poly_summ = (struct bn_poly*)bu_malloc(sizeof(struct bn_poly),"sum");
/* test multiplication and begin checking data */
*poly_summ = bn_poly_mul(&poly_summ,poly_eqn,poly_mul);
/* bn_poly returns a pointer to bn_poly, so i have to declare
* a temporary pointer to find the value. Is this the only way
* or is there a type cast method i am missing?
*/
我想能够做什么:
struct bn_poly poly_summ;
poly_summ = (somethingToConvertReturnVal)bn_poly_mul(&poly_summ,poly_eqn,poly_mul);
/* no memory allocation needed! */