I have a function, void funct (struct *B). It will be called by some instances of struct A. It only takes a pointer to strut B and modify that struct B instance. If struct A has char *name. My question is, can I get access to the A_instance->name? in the funct? If yes, how?
Thank you
I have a function, void funct (struct *B) . It will be called by
Share
You say this is C, which leaves out member functions (C does not have member functions, classes, etc). That means that funct is just a function (not a member of something) and that therefore, you only have the information that is passed in, and the globals. Since neither of those things contain what you want, you can’t get it.
However, you also say that funct is called by ‘some instances of struct A’. This doesn’t make any sense, because in C structures don’t have member functions, and thus can’t make calls. Either you mean that operations on some instances of struct A are calling funct (in which case, my first answer applies), or you really are working with C++, and you’ve got member functions in struct A.
If funct is a member function of struct A, then funct has full access to all the members of the instance of A that called it, and can therefore check ‘name’ directly. Otherwise, we’re back to my first answer.
In order to fix this, you’re either going to need funct to be a member function of struct A (thereby going to C++), or you’re going to need to pass the relevant information into funct.