STB1019 / SkullOfSummer

Learn stuff with less 7-days
Apache License 2.0
5 stars 0 forks source link

Explain comma (,) operator #3

Closed Koldar closed 7 years ago

Koldar commented 7 years ago

It's great inside a function that does not return the values you want in a one line. Useful in logs; for example:

info("my useful log %s", getBufferStringOfEdge(edge_instance, buffer));

here getBufferStringOfEdge returns the number of bytes consumed, but i want the buffer referenced. No problem, just use:

info("my useful log %s", (getBufferStringOfEdge(edge_instance, buffer), buffer));
RedsAnDev commented 7 years ago

Maybe a couple of example can be very useful!

Koldar commented 7 years ago

I agreee. There are few scenarios where comma operator is useful. The one I've quoted in this issue is the one I've encountered during my code developing.