←back to thread

The C23 edition of Modern C

(gustedt.wordpress.com)
397 points bwidlar | 3 comments | | HN request time: 0.001s | 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 #
pjmlp ◴[] No.41850960[source]
Specially relevant to all those folks that insist on "Coding C with a C++ compiler", instead of safer language constructs, and standard library alternatives provided by C++ during the last decades.
replies(3): >>41851031 #>>41851082 #>>41851268 #
com2kid ◴[] No.41851082[source]
Perfectly valid to do if you need to interface with a large C code base and you just want to do some simple OO here and there. Especially if you cannot have runtime exceptions and the like.

This is how I managed to sneak C++ into an embedded C codebase. We even created some templates for data structures that supported static allocation at compile time.

replies(2): >>41851140 #>>41852515 #
f1shy ◴[] No.41851140[source]
What would be an example of "simple OO here and there" that cannot be done cleanly in plain C?
replies(6): >>41851225 #>>41851244 #>>41851407 #>>41851799 #>>41851998 #>>41854294 #
1. com2kid ◴[] No.41854294{4}[source]
You can do anything in C that you want to. Of course one can make v-tables and all of that, and even do inheritance.

But having the "class" keyword is nice. Having built in support for member functions is nice.

Sometimes a person just wants the simplicity of C++ 2003.

(In reality I was working on a project where our compiler only supported C++ 2003 and we had a UI library written in C++ 2003 and honestly pure C UI libraries kind of suck compared to just sprinkling in a bit of C++ sugar.)

replies(1): >>41855255 #
2. throwaway2037 ◴[] No.41855255[source]

    > You can do anything in C that you want to.
How about destructors?
replies(1): >>41856788 #
3. com2kid ◴[] No.41856788[source]
You can obviously build any runtime system you desire in C, including one that parses and executes C code with additional features added in. The wisdom of doing this is questionable.

Though I've actually seen macro systems that do things akin to destructors, although less automatically.