[英]Define and initialise this datatype in C programming
Could someone let me know if this is the correct definition of this datatype and if the way I've initialised it is correct? 有人能告诉我这是否是这个数据类型的正确定义,以及我初始化它的方式是否正确?
typedef int const * (* const DataOne)(const int *);
=> The above datatype shows a constant pointer to a function that takes a pointer to a constant int
as a parameter and returns a pointer to a constant int
. =>上面的数据类型显示了一个指向函数的常量指针,该函数将指向常量
int
的指针作为参数并返回指向常量int
的指针。
=> initialised and declaration: DataOne = &myFunction(7);
=>初始化和声明:
DataOne = &myFunction(7);
typedef int const * (* const DataOne)(const int *);
=> the above datatype shows a constant pointer to a function that takes a pointer to a constant int as a parameter and returns a pointer to a constant int.
=>上面的数据类型显示了一个指向函数的常量指针,该函数将指向常量int的指针作为参数并返回指向常量int的指针。
Correct. 正确。
=> initialised and declaration: DataOne = &myFunction(7);
=>初始化和声明:DataOne =&myFunction(7);
Not correct. 不正确。 Function pointer assignment cannot be made on a function call (ie you cannot have any actual arguments for the parameters).
函数指针赋值不能在函数调用上进行(即,您不能为参数提供任何实际参数)。 Also, DataOne is a type, not a variable.
此外,DataOne是一种类型,而不是变量。 So, it should look something like this:
所以,它应该看起来像这样:
int const * myFunction(const int*);
DataOne myPointer = myFunction; // &myFunction would also work
To declare an equivalent function pointer without a type: 声明没有类型的等效函数指针:
int const * myFunction(const int*);
int const * (* const functionPointer)(const int *) = myFunction;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.