* Boolean to integer - C.
Let's think about the function that return 0 if false, otherwise 1.
=> Naive way : return (e)? 1: 0;
C doesn't support boolean type. Instead, 0 is false, non 0 is true in C.
There is no fixed value to represent TRUE.
But, as defined by 4.5/4, boolean true is promoted to 1, boolean false to 0.
So, we can improve this to
=> Better way : return !!(e);
And this way is also useful because we can get fixed integer value - integer 1 - for TRUE boolean value.
* The ORDER that function PARAMETERS are EVALUATED, is NOT SPECIFIED.
The only requirement is "Those should be fully evaluated before function is called."
'Language > C&C++' 카테고리의 다른 글
[Linux][C/C++] 'select' function - glibc bug?? (0) | 2010.11.19 |
---|---|
[C/C++] Encapsulation tip in C. (0) | 2010.11.12 |
[C/C++] Getting return address… (0) | 2010.11.03 |
[Linux][C/C++] Understanding Signals – User Signal Handler (0) | 2010.10.29 |
[C/C++] type of hard-coded-string. (0) | 2010.09.16 |