News for hackers. Stuff that matters.
Re:The C23 edition of Modern C is now available for free by accelbred on Tuesday October 15, 2024 @02:52PM (#41851853)
C++ can seamlessly include C89 headers.

The C library headers for libraries I write often include C11/C99 stuff that is invalid in C++.

Even when they are in C89, they are often incorrect to include without the include being in an `extern "C"`.

Re:The C23 edition of Modern C is now available for free by nuancebydefault on Tuesday October 15, 2024 @03:03PM (#41851979)
Extern "C" around the prototypes is mandatory, otherwise your linker will search for C++ symbols, which cannot be found in the C libraries you pass it.
Re:The C23 edition of Modern C is now available for free by accelbred on Thursday October 17, 2024 @10:25PM (#41875852)
Not only prototypes but typedefs with function pointers as well.
Re:The C23 edition of Modern C is now available for free by Conscat on Tuesday October 15, 2024 @03:21PM (#41852136)
Clang supports C11 - 23 in C++, as well as some future C features like fixed-point integers. The main pain points with Clang are just the fundamental differences like void* and char, which don't typically matter much at an interoperability layer.
Re:The C23 edition of Modern C is now available for free by flohofwoe on Wednesday October 16, 2024 @02:40AM (#41856217)
There's a lot of subtle differences between 'proper' C and the C subset of C++, since C++ uses C++ semantics everywhere, even for its C subset.

Many C++ coders are oblivious to those differences (myself included before I switched from 'mainly C++' to 'mainly C') because they think that the C subset of C++ is compatible with 'proper' C, but any C code that compiles both in a C++ and C compiler is actually also a (heavily outdated) subset of the C language (so for a C coder it takes extra effort to write C++ compatible C code, and it's not great because it's a throwback to the mid-90s, C++ compatible C is potentially less safe and harder to maintain).

For instance in C++ it's illegal to take the address of an 'adhoc-constructed' function argument, like:

    sum(&(bla_t){ .a = 1, .b = 2, .c = 3, .d = 4 });
(godbolt: https://www.godbolt.org/z/r7r5rPc6K)

Interestingly, Objective-C leaves its C subset alone, so it is always automatically compatible with the latest C features without requiring a new 'ObjC standard'.

Re:The C23 edition of Modern C is now available for free by pjmlp on Wednesday October 16, 2024 @03:26AM (#41856478)
Because Objective-C initial proposal is that everything that isn't touched by Smalltalk like code, clearly in brackets or @annotarions, is plain C.

The pre-processor original compiler, before the GCC fork, would leave everything else alone, blindly copying into the generated C file.

Re:The C23 edition of Modern C is now available for free by kccqzy on Tuesday October 15, 2024 @03:31PM (#41852251)
Yeah plenty of headers first have `#ifdef __cplusplus` and then they add `extern "C"`. And of course even then they have to avoid doing things unacceptable in C++ such as using "new" as the name of a variable.

It takes a little bit of an effort to make a header work on C and C++. A lot less effort than making a single Python file work with Python 2 and 3.

Re:The C23 edition of Modern C is now available for free by flohofwoe on Wednesday October 16, 2024 @02:42AM (#41856228)
The '#ifdef __cplusplus extern "C" { }' thing only removes C++ name mangling from exported symbols, it doesn't switch the C++ language into "C mode" (unfortunately).