How to work with structures in functions.
Hi All,
My question is how You guys prefer to call structure body from function (in embedded systems)?
Code:
Ex1.
STR NewStr;
.
.
fun1(&NewStr)
.
.
void fun1(STR *Ptr)
{
.
.
Ptr->some_variable;
.
.
}
Ex2.
STR NewStr;
.
.
fun1()
.
.
void fun1()
{
.
.
Ptr.some_variable;
.
.
}
What's the different in :
- address stuff
- speed
Point to struct as an argument or as local point?
Quote:
Originally Posted by quzah
Passing a pointer to a structure usually means less overhead (memory) than passing the entire structure itself. Also, if you don't pass a pointer to it, you can't make changes to it that keep once the function has returned.
Quzah.
Hi Quazah,
And what about stuff like that:
Code:
Ex1.
STR NewStr;
.
.
fun1(&NewStr)
.
.
void fun1(STR *Ptr)
{
.
.
Ptr->some_variable;
.
.
}
Ex2.
STR NewStr;
.
.
fun1()
.
.
void fun1()
{
STR *Ptr = NewStr;
.
Ptr->some_variable;
.
.
}
(STR_SPORT_COMMS_DATA *) &GsmData
Ex3.
STR NewStr;
.
.
fun1()
.
.
void fun1()
{
STR *Ptr = (STR *) &NewStr;
.
Ptr->some_variable;
.
.
}