我想将 alloc 作为参数传递,但不知道如何,有人可以帮助我吗?
void parameter(unsigned int argnum, struct resistor* alloc)
{
/*...*/
}
struct resistort
{
const double E6[6];
double E12[12];
const double E24[24];
char e[3];
double value;
double log10val;
double val;
double serielval[2];
double reset;
}rv;
int main(int argc, char *argv[])
{
struct resistor *alloc = NULL;
alloc = (struct resistor *)malloc(sizeof(struct resistor));
parameter(argc, alloc);
}
在参数中我想释放(分配)
我希望它会这样运作:
void parameter(unsigned int argnum, struct resistor* alloc);
但后来我明白了
warning: passing argument 2 of 'parameter' from incompatible pointer type [-Wincompatible-pointer-types]|
note: expected 'struct resistor *' but argument is of type 'struct resistor *'
error: conflicting types for 'parameter'
您收到警告incompatible pointer type
是因为您struct resistor
在声明前使用:
void parameter(unsigned int argnum, struct resistor* alloc)
^^^^^^^^^^^^^^^
在你的程序中, 的声明struct resistor
是在parameter()
函数之后。
您可以通过移动解决这个问题struct resistor
函数之前声明parameter()
或只是做向前声明的struct resistor
前parameter()
功能,就像这样:
struct resistor; //forward declaration
void parameter(unsigned int argnum, struct resistor* alloc)
{
/*...*/
}
struct resistor
{
const double E6[6];
double E12[12];
const double E24[24];
char e[3];
double value;
double log10val;
double val;
double serielval[2];
double reset;
}rv;
int main(int argc, char *argv[])
{
struct resistor *alloc = NULL;
alloc = (struct resistor *)malloc(sizeof(struct resistor));
parameter(argc, alloc);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句