Message from C, C++ discussions

December 2019

— I will try to be online in the future.

— 

I'd like to write a function that stores the frame of the calling function, then "returns" from both the current and the calling function, so that I can later enter the "calling" function at the same position and load the stored frame onto the stack. That way I could easily create generator functions that I'd mainly use for coroutines. Is assembly the only way to implement that? I was hoping for a more portable solution.

— If the condition in the if statement is true it means it's egual to 0 ?

I'm confused, If I call a function like strcmp(string a,string b) and use put it in an if statement, if the strings match means that function will return 0 and so it's true, but for the if a condition is true when it's unequal to 0, why it's confusing?

So the proper way to do it is if(!strcmp(a,b))

Message permanent page

— unequal to 0 means not equal to 0

— Yeah but, strcmp returns 0 when the strings matches but the if works contrary

— strcmp returns 0 for equal strings, yes?
then if (strcmp(str1, str2)) {...} else {...} should go to the else block if str1 and str2 are equal.

Message permanent page

— Do you experience a different behavior?

— Exactly but isn't it more logically if that worked for the if block? the condition is true so don't execute the else?

Message permanent page

— Not sure what you mean.
You can think of it as adding != 0 to the end.
so if (i) the same as if (i != 0).
And in C++ at least it usually highly recommended to use the second form (if it's not a bool operator call that is intended) as it's more clear.

Message permanent page

— So the condition is true when it's not equal to 0, instead for a function like strcmp it's true when it's equal to 0

Message permanent page

— Don't know, I find it a bit confusing

— Thank you Pavel