Then what is your intention? Except for the case where m == -1, which will not happen here unless there is arithmetic overflow, this:Originally Posted by Hodor
is equivalent to:Code:c = !++m;
EDIT:Code:c = 0; m++;
Oh wait, I may have gotten the precedence wrong for the comma operator myself. Oh well. I still don't see the point of using it here.
Last edited by laserlight; 11-19-2013 at 09:58 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
',' is evaluated after '='.
i dont believe in competition in da field of cboard posts, u see, i believe in a collection of posts each 2 be admired for der own personal statement. when in doubt, ask Willy!
I don't want to argue, but I respectfully state with 100% confidence that it is you and whiteflags not understanding the comma operator. The result of the left hand side of expression is discarded, not what the expression does.
I've seen the comma operator used in this way in many projects and I am honestly baffled what's so difficult about it.
I agree: I remembered the precedence table wrongly. (Yes, I checked C99 to be sure prior to editing my previous post.)Originally Posted by Hodor
On the other hand, I would argue that the comma operator is unnecessary conciseness here. Just separate it to two statements.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Two points:
1. +1 for using haskell (although this is a C board... so wtf??)
2. Your solution relies on knowing the end row length, which largely simplifies the solution (Beyond the fact that it's also written in Haskell)
My solution could also have been much simpler with that restriction. Conclusion: Haskell is still useless!
The comma operator is almost always used to obfuscate. I'm not just being salty: Commas are used to separate the arguments in function invocation, but that is not the comma operator being used, because the Standard stipulates that the order in which arguments are evaluated is unspecified. When you can't even be sure at a glance alone that an operator is being used, it's bad in that way, isn't it? Using it effectively would depend entirely of your memory on the rules.
Ok, I've made a much clearer and more efficient implementation
Edit: This is what happens when I'm not allowed to use the comma operatorCode:#include <stdio.h> #include <math.h> /* meh */ int issquare(unsigned n) { int t = sqrt(n + 0.5); return t*t == n; } int istrinum(unsigned n) { return issquare(8 * n + 1); } /* could probably be improved */ unsigned prevtrinum(unsigned n) { int i, largest = 0; for (i = 0; i < n; i++) if (istrinum(i)) largest = i; return largest; } /* could probably be improved */ unsigned linelen(unsigned n, unsigned cnt) { unsigned prev; prev = prevtrinum(n); if (prev > 0) cnt = linelen(prev, cnt + 1); else cnt++; return cnt; } /* could probably be improved */ void floyd_r(unsigned n) { unsigned len, prev, i; static const char delim[] = {'\n', ' '}; if (n == 0) return; prev = prevtrinum(n); if (prev > 0) floyd_r(prev); len = linelen(n, 0); for (i = len; i > 0; i--) printf("%2d%c", n - i + 1, delim[i > 1]); } int main(void) { floyd_r(91); return 0; }
Last edited by Hodor; 11-20-2013 at 01:12 AM.
ok after reading the 27 posts, all i can say is O.....M....G......
This post went a little nuts didnt it???
not to mention doing all the work for the new kid.....
You're all wrong. This is the correct solution: