As a warning: While C99 is a really nice language - especially over C89 - please note that the Visual Studio C compiler still does not support the full C99 specification, and it is not possible at all to compile C99 as C++ code (which sometimes is useful). I usually recommend to write library-level code in the "subset of C99 which compiles both in C and C++ mode on GCC, clang and MSVC". This is basically a version of…
Thanks for the comment, I might steal your "subset of C99 which compiles both in C and C++ mode on GCC, clang and MSVC" quote and put it in the article if that's ok ;)
How to write better game libraries
111–120 of 129 posts
Re: How to write better game libraries
#112Earlier quoted context omitted.
- reasonable organized code doesn't take hours. even template heavy code is quite fast these days - templates are type safe. it is just the error messages are not helpful a lot of times. C++20's concepts should help - circular references. that's a thing in C as well. as soon as you need interact with your libraries user to allocate/deallocate resources. C++ has a large surface to interact with. Yes you can shot yours…
Templates are duck typing at C++ compile time (which is their runtime). Yes, concepts should help. 'Modules via copy-and-paste' (= #include) is what I would hurl at C++ these days. Though they are working on that as well, I heard. Though https://vector-of-bool.github.io/2019/01/27/modules-doa.html doesn't sound hopeful.
That description only applies of you venture into the dark realm of template metaprogramming, and anyone who ventures into those lands is wise enough to understand that the tool is not the one to blame if one decides to abuse a feature to apply it in a way it was not (initially) designed to be used.
Re: How to write better game libraries
#113> Not everyone wants to use C++ (some prefer C). This could be very well flipped over. If I have the source available, I'd much rather deal with C++ bindings.
Hi, I mention in the article that "It is easier in general for a C++ user to use a C library than it is for a C user to use a C++ library." which is where the advice comes from.
C++ ABIs are rather complex and much harder to interface with. The existence of concepts like virtual functions and exceptions significantly complicates the implementation of foreign language interfaces.
https://wiki.osdev.org/System_V_ABI https://itanium-cxx-abi.github.io/cxx-abi/abi.html
Re: How to write better game libraries
#114Earlier quoted context omitted.
Thanks for the comment, I might steal your "subset of C99 which compiles both in C and C++ mode on GCC, clang and MSVC" quote and put it in the article if that's ok ;)
Is there a benefit to building C code with a C++ compiler?
Re: How to write better game libraries
#115Earlier quoted context omitted.
Do note where this article resides. Casey Muratori (of Handmade Hero, a game dev tutorial project) is a self-proclaimed anything-not-C hater. A community has formed around his project, and has, of course, adopted his hard-line stance.
Interesting, thanks for the hint.
Re: How to write better game libraries
#116Earlier quoted context omitted.
Templates are duck typing at C++ compile time (which is their runtime). Yes, concepts should help. 'Modules via copy-and-paste' (= #include) is what I would hurl at C++ these days. Though they are working on that as well, I heard. Though https://vector-of-bool.github.io/2019/01/27/modules-doa.html doesn't sound hopeful.
> Templates are duck typing at C++ compile time (which is their runtime). That description only applies of you venture into the dark realm of template metaprogramming, and anyone who ventures into those lands is wise enough to understand that the tool is not the one to blame if one decides to abuse a feature to apply it in a way it was not (initially) designed to be used.
Concepts would presumably enforce some kind of thematic relationship between different overloads for the same group of functions and operators. (At least that's how we are doing it in Haskell with typeclasses. But we have a more forgiving syntax that allows us to make new operators.)
Re: How to write better game libraries
#117Earlier quoted context omitted.
I once forked a C library, porting some parts to C++ in the process: https://github.com/Const-me/nanovg/ I’ve retained original C API, only used C++ in the implementation. Then I’ve got an e-mail from a developer who asked a few things how to back port my changes to C. I answered their questions, but I was curious why. They replied it’s because Objective C and iOS. Personally, I haven’t been developing for iOS for se…
That developer must be misinformed. I have been developing a native component that needs to interface with C++ APIs from the app and Objective C APIs from iOS. The only thing you need to remember is to not mix exceptions from C++ and Objective C. The object models are also incompatible, but the compiler prevents you from mixing them.
Re: How to write better game libraries
#118Earlier quoted context omitted.
> modern C++ > pleasant Nice joke. Hour-long compilations, type-unsafe templates with unreadable errors, and circular references are considered pleasant now?
- reasonable organized code doesn't take hours. even template heavy code is quite fast these days - templates are type safe. it is just the error messages are not helpful a lot of times. C++20's concepts should help - circular references. that's a thing in C as well. as soon as you need interact with your libraries user to allocate/deallocate resources. C++ has a large surface to interact with. Yes you can shot yours…
Templates are of course type unsafe, I'm not sure why you're lying while also admitting that they will only become type-safe in C++20.
Circular references deserves more comment: there is a difference between unmanaged and managed memory. C is unapologetically unmanaged, which cements its position on the embedded scene. But C++ has tried to be the in-between language: you have your raw pointers, and you have your refcount GC (“smart pointers"). And the thing that strikes me is the Cppistas have overwhelmingly chosen GC, but their language's GC is the worst kind, with circular references, performance costs (yes, smart pointers have a lot) and ultimately without memory safety (as raw pointers are still there). They've truly chosen tge worst of both worlds yet don't have the integrity to admit that the future is with managed, traced GC. C++ is like driving a car from the fifties and bragging about how comfortable and modern it is with that new internal combustion engine!
Re: How to write better game libraries
#119Earlier quoted context omitted.
Templates are duck typing at C++ compile time (which is their runtime). Yes, concepts should help. 'Modules via copy-and-paste' (= #include) is what I would hurl at C++ these days. Though they are working on that as well, I heard. Though https://vector-of-bool.github.io/2019/01/27/modules-doa.html doesn't sound hopeful.
> Templates are duck typing at C++ compile time (which is their runtime). That description only applies of you venture into the dark realm of template metaprogramming, and anyone who ventures into those lands is wise enough to understand that the tool is not the one to blame if one decides to abuse a feature to apply it in a way it was not (initially) designed to be used.
Re: How to write better game libraries
#120>> C is the lingua franca of programming I don't have the exact numbers, but this seems debatable.
It's the lingua franca in that it's the standard for interoperating. Every high level language I've used has had at least one C FFI readily available.