I write type-safe generic data structures in C
131–140 of 196 posts
Re: I write type-safe generic data structures in C
#132> Structurally identical types will be considered the same type in GCC 15 and Clang later in 2025 thanks to a rule change Beware that only tagged unions are considered the same type under the new rule, provided they have the same structrure and the same tag. The List(T) macro should be changed to generate a different tag for each different T. Which is trivial (with ##) for simple one-word types, but impossible for ev…
I don't get it. Tagged union is just a design pattern.
Re: I write type-safe generic data structures in C
#133Earlier quoted context omitted.
"has no parameters" is not the same as "cannot take arguments". Defining `int main()` does not stop the runtime from passing the usual 3 arguments (typically named argc, argv, envp), it only means that no parameters are bound to those arguments. Technically it's no problem to have a C function ignore its arguments by not binding parameters. Way too many programmers seem to not understand the difference between parame…
Surely part of the problem is having a distinct term and handling for parameters passed to functions. What is the point? It seems confusing with no upside.
Re: I write type-safe generic data structures in C
#134Earlier quoted context omitted.
Do you have a couple of real world examples?
Any established C codebase, for example the kernel or Postgres? Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.
Obviously you mean the Linux kernel, specifically. Also C++ has gotten a lot better since 2003 and before.
Examples of C++ usage in commercial codebases:
- anything Nintendo has written since 2010 (including microkernel, entire OS and all, for 3DS and Switch 1/2)
- well-known, high performing databases like ScyllaDB
> you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.
With the exception of exceptions (and coroutines but that's easily customizable), it's merely a standard library thing and doesn't affect language features (incl. language features exposed as std:: funcs/traits)
C++ has got a bad rep because it never fixes broken stdlib parts due to API and ABI concerns, and has many footguns due to this, that might make Rust and C better choices in corporate environments. However, IMHO, C++ is a much better language than C for personal projects, or when having a team of experienced folks.
Re: I write type-safe generic data structures in C
#135Dude the ship has sailed.
Not sure what you mean by that, but if you're trying to imply that C is not relevant: https://www.tiobe.com/tiobe-index/ Plus an article about C was at the top of hacker news all day today.
C is still relevant, but TIOBE numbers are not.
Re: I write type-safe generic data structures in C
#136Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"
I was really disappointed that Microsoft decided to backtrack on C++'s is the future, after the new found Linux and FOSS love.
https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...
https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...
Not that it matters much, as nowadays C and C++ have a new policy at Microsoft due to goverments and cyberlaws.
https://azure.microsoft.com/en-us/blog/microsoft-azure-secur...
https://blogs.windows.com/windowsexperience/2024/11/19/windo...
Re: I write type-safe generic data structures in C
#137Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"
because i work on a legacy project that is coupled to safety regulations and other quality guarantees, and we cannot just simply roll out a solution ported to c++ on the next release, or even tenth, so perhaps we make it work until we can. however we can set a standard and expectation for new projects to use c++, and we do and set an expectation to target a specific std. i see this sentiment quite a lot on hackernews…
Re: I write type-safe generic data structures in C
#138Re: I write type-safe generic data structures in C
#139Earlier quoted context omitted.
Do you have a couple of real world examples?
Any established C codebase, for example the kernel or Postgres? Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.
Anecdotally, GCC and GDB successfully (and incrementally) switched to C++ form C in the recent past.
The Linux kernel will never do it for ideological reasons of course.
I don't know about Postgres.
Re: I write type-safe generic data structures in C
#140Earlier quoted context omitted.
You can still write the extension in C++ and expose an extern "C" interface.
That's possible, but then the people building your extension need a C++ toolchain. The question was "please provide examples where switching to C++ involves jumping through even more hoops", and in my view requiring downstream to use a C++ environment when they're expecting to use a C environment qualifies.
Unless of course the project is using such a old compiler.