[英]Can I use a struct in a way that does not exist in the header file implementation?
So I am a Java and C# person recently doing some stuff C. I have a header file that would have a function void update(struct process* foo, float measurements)
and in the implementation of the header file (the .c file) I will have the function: 因此,我最近是一名Java和C#的人,正在做一些C的工作。我有一个头文件,该文件具有功能
void update(struct process* foo, float measurements)
并且在头文件的实现中(.c文件)我将具有以下功能:
void update(struct process* p,float measurements)
{
*p.speed = *p.speed + measurements;
*p.time = *p.time + 1;
*p.noise = *p.noise + ((measurements)/100);
}
Now in Java I would have to import the class process and it would be all good. 现在,在Java中,我将必须导入类过程,这将很好。 However in the .c implementation how would I do that without declaring the struct in the .c file (which would be pointless since I want to pass parameter from another module using it)?
但是,在.c实现中,我如何在不声明.c文件中的结构的情况下做到这一点(这将毫无意义,因为我想使用该模块从另一个模块传递参数)?
I am quite new in C and may be it's a very basic question but I did an hour search in internet ended up not finding what I am looking for. 我是C语言的新手,也许这是一个非常基本的问题,但是我在互联网上进行了一个小时的搜索,最终没有找到我想要的东西。 Maybe my keywords were just poorly chosen.
也许我的关键字选择不正确。
You include the file where process
structure definition is. 您包括
process
结构定义所在的文件。
As @AusCBloke noticed, you'll either use (*p).
正如@AusCBloke所注意到的,您将使用
(*p).
to dereference struct pointer and access its member, or p->
which is syntactic sugar for (*p).
取消引用结构指针并访问其成员,或者
p->
是(*p).
语法糖(*p).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.