The `any*` fat pointer in C3 is a version of this: <a href="https://c3-lang.org/anyinterfaces/" rel="nofollow">https://c3-lang.org/anyinterfaces/</a> Once this is available the step to embedding some runtime type information isn't far.
I had worked on something similar around 11-12 years back ( no way close to perfect or of any use :) )
<a href="https://github.com/nautical/CBullet">https://github.com/nautical/CBullet</a><p>Basically you can do something like this in c :<p>var value;<p>value = data(100);<p>// or<p>value = data(0, 2, 3, 4, 5, 6);
Polymorphic types are certainly useful, and I wish C had a better way to go about it, but this proposal feels like an odd patch to C's type system. Especially this part:<p>```
Using a run-time value of type _Type T in _Var(T) can be allowed in general (and is useful), but
needs to be restricted to contexts where full type information is not required at compile-time.
```<p>Semantic rules that conditionally apply only in some contexts is a common tendency of the C++ standard that many C programmers often dislike.
As a (not so) minor point -<p>It's worth keeping in mind that code aesthetics is an important aspect of C codebases. There's a lot of C code that is exclusively lowercase, sans the macros. So introducing keywords like _Type and _Var will serve to hinder their adoption, because it'd make the code that much more "ugly". Just like what happened with _Generic - a reasonable feature, bad keyword selection -> barely any field use.
IMHO, the C committee should just copy a subset from C++, in addition to having new features for free, you also make sure c and c++ are 100% compatible.
You can still use virtual function calls in plain C, you just do things the same way that C++ does things internally. Your first member of the struct is a Vtable, and you need to assign that member when you create the object. Your first parameter for the virtual method calls is a "this" pointer.
> <i>The following for [sic] declaration [sic] are then all equivalent:</i><p><pre><code> int i;
int *ip;
typeof(i) *i;
_Var(_Typeof(i)) *i;
</code></pre>
What? How are "int i" and "int *ip" equivalent?<p><i>_Var(_Typeof(i)) ident</i> strikes me as incredibly silly. The type value produced by _Typeof(i) should be directly usable as a declaration specifier, without requiring hoisting to a name.<p>FFS, GNU C has had a sane typeof working for years.<p>To bind a type to an identifier, we don't need a _Type type at all. <i>typedef</i> does this!<p>I.e. not:<p><pre><code> _Type x = int;
</code></pre>
but<p><pre><code> typedef int x;
</code></pre>
Existing, decades-old <i>typedef</i> is how you bind an identifier to a compile-time type value. There is no need to do this via a _Type type specifer, which then forces us to move the type we want into the initializer. We use the <i>typeof</i> storage class specifier, which then lets us have the type we want as another specifier, and we don't need an initializer.<p>This works in GNU C:<p><pre><code> int x;
typedef typeof(x) tx; // same as typedef int tx;
</code></pre>
The problem of declared, named containers to capture type is long solved.
Is it just me, or are disillusioned C++ refugees who've gone back to C now trying to wreck it a second time? Probably just me. Since the 80's, C++ served as an excellent decoy to absorb craziness and keep C sane.
I use C at my day job and our company works with ANSI C. I believe it's C89. I was curious to find out - who's using C23 in prod? Please let me know in the comments. I'm super curious!