I write type-safe generic data structures in C
91–100 of 196 posts
Re: I write type-safe generic data structures in C
#92Another way is to not try to write generic data structures. When you tailor them to the use case you can simplify. The #1 data structure in any program is array.
When all you have are arrays, everything looks like a problem you solve with arrays. There are quite a few problems that specialised containers are suited for, that's why they were created.
The situation where you need a red black tree with 10 different key/value combos isn’t real.
Re: I write type-safe generic data structures in C
#93Earlier quoted context omitted.
If the C compiler accepts it, it is C.
Pedantically, the preprocessor is an entirely separate language. The lexing, parsing, expressions, and semantics are totally distinct. The preprocessor is usually implemented as a completely independent program. My first C compiler did integrate the preprocessor with the C compiler, but that was for performance reasons. Currently, ImportC runs cpp and then lexes/parses the resulting C code for use in D.
Re: I write type-safe generic data structures in C
#94Re: I write type-safe generic data structures in C
#95Earlier quoted context omitted.
Pedantically, the preprocessor is an entirely separate language. The lexing, parsing, expressions, and semantics are totally distinct. The preprocessor is usually implemented as a completely independent program. My first C compiler did integrate the preprocessor with the C compiler, but that was for performance reasons. Currently, ImportC runs cpp and then lexes/parses the resulting C code for use in D.
It is part of the C standard. Whether it is part of a separate binary is an implementation choice.
Re: I write type-safe generic data structures in C
#96Re: I write type-safe generic data structures in C
#97Re: I write type-safe generic data structures in C
#98Earlier quoted context omitted.
FWIW, as far back as 2015 my feature check library documents Visual Studio as supporting "__typeof".[1] Note the leading but not trailing underscores. Perhaps I was mistaken, but I usually tested that sort of thing. It's also possible __typeof had slightly different semantics. [1] See https://github.com/wahern/autoguess/blob/b44556e4/config.h.g... (that's the 2015 revision, but HEAD has the same code).
msvc 19.39 is the first to support it, which I mention in the article. You can confirm it didn't work up through 19.38 in godbolt [1]. I don't use Visual Studio, so I don't know what version of that first started using msvc 19.39 [1] https://godbolt.org/z/M7zPYdssP
Digging through some old code of mine (circa 2009) I found this bit:
#elif _MSC_VER >= 1310
#define typeof(type) __typeof(type)
So somehow I had the impression Visual Studio .NET 2003 (7.1)[1] added __typeof. I'm still holding out hope someone will come to my rescue and reply that once upon a time MSVC had __typeof, but removed it. But for now it seems past me is gaslighting present me.[1] See https://learn.microsoft.com/en-us/cpp/overview/compiler-vers... for mapping between Visual Studio versions and _MSC_VER.
EDIT: Ah ha! It seems Microsoft did support __typeof, but perhaps only for "managed" C++ (aka C++ .NET)?
> One thing to watch out for when using the __typeof operator in managed C++ is that __typeof(wchar_t) can return different values depending on the compilation options.
Source: https://learn.microsoft.com/en-us/archive/msdn-magazine/2002... (See also https://learn.microsoft.com/en-us/archive/msdn-magazine/2005...)
Re: I write type-safe generic data structures in C
#99Dude the ship has sailed.
Plus an article about C was at the top of hacker news all day today.
Re: I write type-safe generic data structures in C
#100Earlier quoted context omitted.
When all you have are arrays, everything looks like a problem you solve with arrays. There are quite a few problems that specialised containers are suited for, that's why they were created.
And you can write them when you need them. The situation where you need a red black tree with 10 different key/value combos isn’t real.