←back to thread

The C23 edition of Modern C

(gustedt.wordpress.com)
397 points bwidlar | 1 comments | | HN request time: 0s | source
Show context
belter ◴[] No.41850897[source]
Important reminder just in the Preface :-)

Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up"

replies(6): >>41850960 #>>41851047 #>>41851166 #>>41851693 #>>41853183 #>>41855660 #
jpcfl ◴[] No.41851047[source]
Bjarne should have called it ++C.
replies(2): >>41851328 #>>41854437 #
card_zero ◴[] No.41851328[source]
Because people choose to use pre-increment by default instead of post-increment?

Why is that?

replies(4): >>41851427 #>>41851557 #>>41851650 #>>41853498 #
jejdjdbd ◴[] No.41851427[source]
Why would you use post increment by default? The semantics are very particular.

Only on very rare occasions I need post increment semantics.

And in those cases I prefer to use a temporary to make the intent more clear

replies(3): >>41851532 #>>41852965 #>>41856255 #
card_zero ◴[] No.41851532[source]
People seem to mostly write a typical for loop ending with ; ++i){

But I write ; i++){ and seeing it the other way round throws me off for a minute, because I think, as you put it, why would you use those very particular semantics?

But I guess this is only a semantic argument.

replies(4): >>41851721 #>>41852277 #>>41852443 #>>41852595 #
Quekid5 ◴[] No.41852443[source]
I've seen either style, but it the argument about which is proper is pointless. Any modern compiler will optimize either equally well, unless you're doing something that actually depends on the order of the increment.
replies(1): >>41852642 #
1. kanbankaren ◴[] No.41852642[source]
No, for fundamental datatypes pre/post-increment doesn't matter, but for classes that overload those operators, the postfix form creates a temporary object hence people write

for(auto it = begin(v); it != end(v); ++it)