I am using structs in my code. I don't know which is better or a more standar style about using functions with structs. In my case I pass by value to a function several bytes of a struct, not the entire struct. Do you seniors pass by value or by reference struct to functions when you don't need to pass much bytes?
Using passage by reference allow you to pass all the structure to the function in one time.
More over it let you able to return an integer value at the end of the function to know if it ended normaly and have updated fields of the structure and use them in others functions.
Just one more question. What if I need also pass the struct by reference to another function inside the function to which I have passed it by reference. I mean I would like to pass a struct by reference to a function and then inside this function pass again the struct by reference to another function. How do you seniors do this? something like below?
typedef struct
{
/* define data here */
} structMessageRx;
int PORTS_PINS_Write_Port(structMessageRx *MessageRx)
{
x = MessageRx->BYTES.BYTE_4;
New_Function(MessageRx)
That is correct with unions and structures.
Pointers always have the same size (32 bits in Windows or less in embedded), so if this pointer points to a char you will send 4 bytes instead of 1, but if it points to a huge structure it will be 4 bytes long as well.