Mom*_*gil 2 c parameters struct pointers function
在我用CI编写的一个应用程序中,有一个结构被声明为另一个结构的成员:
struct _test
{
int varA;
//...
struct _small
{
int varB;
//...
} small;
} test;
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个访问varB上面的函数,但我不希望它访问整个结构test,也就是说,我不想这样做:
#include <relevant_header>
void myFunction()
{
test.small.varB = 0;
}
Run Code Online (Sandbox Code Playgroud)
相反,我想只将small结构作为参数传递给该函数; 这样的事情:
#include <relevant_header>
void myFunction(struct _test::_small* poSmall)
{
poSmall->varB = 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是我不知道怎么做,也就是说,上面的代码编译得不对(我想它只是C++语法).那么我怎样才能在C代码中执行此操作 - 将指针传递给在另一个struct中声明的结构?我无法在SO和Google中找到任何相关内容.
做就是了:
void myFunction(struct _small *poSmall)
{
poSmall->varB = 0;
}
Run Code Online (Sandbox Code Playgroud)
范围struct _small不限于其外部结构.