|Feb 21, 2013, 09:13 PM||#1|
Any thoughts on the comma operator (C/C++/Obj-C?)
I recently decided to insert a few comma operators into the output lines of my C++ code and I feel like they've cleaned up my code a lot.
For example, I had this code:
cout << "Can't place " << v << " at " << x << ", " << y << endl << "Add: "; printBitsForInt(mask); cout << "Old: "; printBitsForInt(conflicts[v-1]); cout << endl;
And by introducing a few sequence points I feel like I was able to clean it up quite a bit, improve legibility, and reduce the amount of space it takes up.
cout << "Can't place " << v << " at " << x << ", " << y << endl << "Add: ", printBitsForInt(mask), cout << endl; << "Old: ", printBitsForInt(conflicts[v-1]), cout << endl;
I'm wondering if I could use the same basic idea in the future with some C or Obj-C code.
Also, is there any real difference between using the comma operator and inserting a semicolon? I feel like the compiler probably generates the same code for both, wouldn't it?
Are there any other good uses for the comma operator?
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|iPad: Exclamation point instead of comma when I type||flyersgl||iPad||1||Dec 28, 2013 04:01 AM|
|convert comma to decimal point in excel||userjoy||Mac Applications and Mac App Store||5||Feb 14, 2013 07:54 AM|
|# arithmetic operator for Bash||BerGaur||OS X||1||Dec 16, 2012 09:14 AM|
|4S - no operator signal||Moccasin||iPhone Tips, Help and Troubleshooting||0||Jul 11, 2012 11:58 PM|
|Removing comma from a list||fhill2||Mac Programming||8||Jun 25, 2012 01:07 PM|
All times are GMT -5. The time now is 07:10 AM.