|
|
#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: 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. Code:
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?
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
|
|
|
0
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 03:59 PM.







Threaded Mode