String functions, passing structure instead of pointer ? #2411
-
Hi, Some string functions have mg_str pointers as arguments while others have the direct mg_str structure as arguments. Is there a reason to not always use mg_str pointers in all functions ? If I remember correctly passing mg_str structure as arguments makes a copy of the structure, which is not important because the structure is tiny, but the question seems still valid :) Regards. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@dev31337 the reason is to have an ability to craft arguments on the fly. Consider foo(mg_str("hello")); vs struct mg_str arg = mg_str("hello");
foo(&arg); As you've pointed out, the struct is tiny so passing a struct is not an issue. |
Beta Was this translation helpful? Give feedback.
-
Thank for the quick reply, that makes sense now ! |
Beta Was this translation helpful? Give feedback.
@dev31337 the reason is to have an ability to craft arguments on the fly. Consider
vs
As you've pointed out, the struct is tiny so passing a struct is not an issue.