1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | my_thing_t thing = {}; thing.a = 23; thing.b = {5, 0}; thing.c = 25553; thing.d = 23; thing.e = 0.23; thing.f = "abc"; thing.g = 23; thing.h = 'k'; thing.i = 23; thing.j = 0; thing.k = thing.j + 4; thing.l = {2341}; thing.m = 223; thing.n = 2343; do_something_with_thing(program_state, thing); |
This functions gets called in about 40 different places ~5 times per second. (with different arguments)
I could pass all those struct members as parameters to the function instead of creating a struct for this, but imagine the struct is much bigger than that. This would make the code mode readable (at least I think so?).
Now, imagine that function is about 50 lines of code. What should I do here?
- Make the function inline and pass `thing` by value
- Make the function inline and pass `thing`'s reference? (probably never good, right?)
- Allocate `thing` on the heap and pass it's reference?
- Pass everything as arguments even though it could be more than 20 arguments?
Is this something I should not do?
Isn't this too much like OOP? (in the sense that I'm basically creating an object and calling its method)
What are better alternatives?