In my network-programming course, I've come across the following function, which initializes a struct of type _body
:
_body f1(int pkg_type, int key_len, void* key, int value_len, void* value) {
_body new_body;
new_body.key_len = 0;
new_body.key = NULL;
new_body.value_len = 0;
new_body.value = NULL;
return new_body; }
Another function than calls this function to initialize the struct given some conditions:
_body f2(void* pkg_body, another_struct pkg_header) {
_body new_body;
new_body = f1(pkg_header.pkg_type, pkg_header.key_len, (pkg_header.key_len) ? pkg_body : NULL, pkg_header.value_len, (pkg_header.value_len) ? pkg_body + pkg_header.key_len : NULL);
return new_body;}
Question: What does the line:
new_body = f1(pkg_header.pkg_type, pkg_header.key_len, (pkg_header.key_len) ? pkg_body : NULL, pkg_header.value_len, (pkg_header.value_len) ? pkg_body + pkg_header.key_len : NULL);
do exactly? How does it work and how can I understand it in terms of if
conditions?
Note that I'm not providing explicit definitions of the structs and their values as my question is merely about understanding syntax.