Live data from Hacker News

The C23 edition of Modern C

gustedt.wordpress.com

111–120 of 360 posts

Re: The C23 edition of Modern C

#111
post #93

Earlier quoted context omitted.

Does C automatically wrap? I thought you need to pass `-fwrapv` to the compiler to ensure that.

-fwrapv is for signed integer overflow not unsigned .

Yes, as unsigned overflow is fine by default. AFAIK the issue was originally that there were still machines that used ones complement for describing negative integers instead of the now customary twos complement.

Re: The C23 edition of Modern C

#112
post #15
post #2

Important reminder just in the Preface :-) Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up"

A couple of months ago, in the company I work, there was a talk from HR, where they explained how to make a good CV (the company is firing lots of people). She say: "if you have experience in programming C, you can writing just that, or, if you have lots of experience in C, is customary to write ``C++ Experience'' " Sooo... yeah... I should definitely change company!

How many pluses until you should just say you have D experience?

Re: The C23 edition of Modern C

#114
post #76
post #45

Earlier quoted context omitted.

>Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up" Where "mixing C/C++" is helpful: - I "mix C in with my C++" projects because "sqlite3.c" and ffmpeg source code is written C. C++ was designed to interoperate with C code. C++ code can seamlessly add #include "sqlite3.h" unchanged. - For my own code, I take advantage of "C++ being _mostly_ a superset of C" such as using old-style C printf…

> C++ code can seamlessly add #include "sqlite3.h" unchanged. Almost seamlessly. You have to do extern “C” { #include "sqlite3.h" } ( https://isocpp.org/wiki/faq/mixing-c-and-cpp#include-c-hdrs-... )

If we're nitpicking then sqlite3.h already has `#ifdef __cplusplus` and `extern "C" {`. So yes, from the user's perspective it is seamless. They do not need to play the `extern "C" {` game.

Re: The C23 edition of Modern C

#115
post #62

Earlier quoted context omitted.

Why use this operator? Like most C and C++ features the main reason tends to be showing off, you learned a thing (in this case that there are four extra operators here) and so you show off by using it even if it doesn't make the software easier to understand. This is not one of those beginner -> journeyman -> expert cycles where coincidentally the way you wrote it as a beginner is identical to how an expert writes it…

The idiomatic void strcpy(char *s, char *t) { while (*s++ = *t++) ; } (straight from K&R) wouldn’t work without it.

Which many people find unreadable compared to other versions.

Re: The C23 edition of Modern C

#116
post #73

Earlier quoted context omitted.

I don't disagree, but these are in the ~2% convenience at most. With the huge baggage of including C++ in a project. The cost of learning C++ easily outweighs all those benefits. If you happen to have a proficient C++ team (that actually know embedded), go for it!

Speaking more broadly than just the std implementation, but result types like optional shouldn't be a 2% convenience, they should be used in most function calls that return errors. Rust is the obvious example here.

If you argue for Rust I'm all for it, arguably much less of a learning curve than C++ too.

Re: The C23 edition of Modern C

#117
post #102
post #72

Earlier quoted context omitted.

UB is does not automatically make things unsafe. You can have a compiler that implements safe defaults for most UB, and then it is not unsafe.

That's implementation defined behavior, not undefined behavior. Undefined behavior explicitly refers to something the compiler does not provide a definition for, including "safe defaults."

Compilers are not prohibited to provide their own definition for UB, that's how UBsan exists.

Re: The C23 edition of Modern C

#118
post #82
post #72

Earlier quoted context omitted.

UB is does not automatically make things unsafe. You can have a compiler that implements safe defaults for most UB, and then it is not unsafe.

By definition UB cannot be safe.

this depends on your choice of definition for "safe"

Re: The C23 edition of Modern C

#119
post #2

Important reminder just in the Preface :-) Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up"

My brief foray into microcontroller land has taught me that C and C++ are very much mixed.

It's telling that every compiler toolchain that compiles C++ also compiles C (for some definition of "C"). With compiler flags, GCC extensions, and libraries that are kinda-sorta compatible with both languages, there's no being strict about it.

_My_ code might be strict about it, but what about tinyusb? Eventually you'll have to work with a library that chokes on `--pedantic`, because much (most?) code is not written to a strict C or C++ standard, but is "C/C++" and various extensions.

Re: The C23 edition of Modern C

#120
post #45

Earlier quoted context omitted.

>Takeaway #1: "C and C++ are different: don’t mix them, and don’t mix them up" Where "mixing C/C++" is helpful: - I "mix C in with my C++" projects because "sqlite3.c" and ffmpeg source code is written C. C++ was designed to interoperate with C code. C++ code can seamlessly add #include "sqlite3.h" unchanged. - For my own code, I take advantage of "C++ being _mostly_ a superset of C" such as using old-style C printf…

The entire I/O streams (where std::cout comes from) feature is garbage, if this was an independent development there is no way that WG21 would have taken it, the reason it's in C++ 98 and thus still here today is that it's Bjarne's baby. The reason not to take it is that it's contradictory to the "Don't use operator overloading for unrelated operations" core idea. Bjarne will insist that "actually" these operators so…

> The biggest problem is that today C++ doesn't have a way to implement this for your own types easily

I’m not sure about the stdlib version, but with fmtlib you can easily implement formatters for your own types. https://fmt.dev/11.0/api/#formatting-user-defined-types

Post reply on HN