as3rdaccount
as3rdaccount

Reputation: 3931

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.

Upvotes: 0

Views: 91

Answers (1)

nullpotent
nullpotent

Reputation: 9260

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

Upvotes: 1

Related Questions