简体   繁体   中英

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:

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. 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)?

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. Maybe my keywords were just poorly chosen.

You include the file where process structure definition is.

As @AusCBloke noticed, you'll either use (*p). to dereference struct pointer and access its member, or p-> which is syntactic sugar for (*p).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM