5 comments

  • mjs0128 minutes ago
    Some unmentioned incompatibilities I&#x27;ve encountered that makes a C header not directly usable in C++:<p>- C `_Atomic(T)` and C++ `std::atomic&lt;T&gt;`. C++23 has C compatible header `stdatomic.h` that defines `_Atomic(T)`, but it&#x27;s still problematic<p>- C `_Noreturn&#x2F;noreturn` and C++ `[[noreturn]]`. C23 `[[noreturn]]` makes them compatible<p>- C inline and C++ inline are different. Good news is their `static inline` are the same<p>- C has anonymous struct. C++ doesn&#x27;t. Both have anonymous union though
  • gritzko3 minutes ago
    C is dealing with bits and bytes. C++ is building a tower of abstractions, one on top of another. For this dramatic difference in approach, the incompatibilities are surprisingly small.
  • jalospinoso3 days ago
    I wrote this after repeatedly seeing experienced C programmers hit the same sharp edges while moving into modern C++ codebases.<p>Many of these differences are intentional and defensible from the C++ side. But some are still surprising because they invalidate patterns that were historically common, performant, or idiomatic in C.<p>The interesting part to me isn’t &quot;C vs C++,&quot; but where the languages diverged philosophically: object lifetime vs raw storage, stronger type systems, implicit conversions, ABI and optimization assumptions, and the boundary between &quot;portable&quot; and &quot;works on my compiler.&quot;<p>I’d also be curious which C constructs people still genuinely miss in modern C++. For me, restrict is still near the top of the list.
    • hgs328 minutes ago
      Not sure if you&#x27;re aware, but defer is proposed for C2Y [1]. It&#x27;s already available in Clang behind a compiler flag. It <i>is</i> interesting how the languages continue to diverge.<p>[1] <a href="https:&#x2F;&#x2F;www.open-std.org&#x2F;JTC1&#x2F;SC22&#x2F;WG14&#x2F;www&#x2F;docs&#x2F;n3734.pdf" rel="nofollow">https:&#x2F;&#x2F;www.open-std.org&#x2F;JTC1&#x2F;SC22&#x2F;WG14&#x2F;www&#x2F;docs&#x2F;n3734.pdf</a>
      • pjmlp24 minutes ago
        Because the communities aren&#x27;t the same.<p>C++ is 1990&#x27;s Typescript for C++, while C folks still think is a portable Assembly instead of designed to an abstract machine model.<p>As such C++ community embraces high level abstractions and type systems improvements, whereas C wants to still code as targeting classical hardware.
    • pjmlp26 minutes ago
      I appreciate that restrict isn&#x27;t there, because it is yet another UB source, programmer knows not to do errors kind of attitude, and secondly no one seems to care enough to write a language proposal for it.
  • AdieuToLogic47 minutes ago
    From the article:<p><pre><code> In 2019 I wrote a short survey of C constructs that do not work in C++. The point was not that C is sloppy or that C++ is superior. The point was that C++ is not a superset of C, and that C programmers crossing the border should know where the checkpoints are. </code></pre> C++ was a superset of C 30-ish years ago. Now, as the author correctly identifies, it is not as both have taken different evolutionary paths.
    • pjmlp28 minutes ago
      Already in C++98 there were differences.<p>?: has another execution priority.<p>Implicit cast scenarios are reduced in C++.
  • dhruv300625 minutes ago
    &gt; restrict: a C promise, not a C++ contract<p>This takes the cake.