Live data from Hacker News

I write type-safe generic data structures in C

danielchasehooper.com

111–120 of 196 posts

Re: I write type-safe generic data structures in C

#112

Earlier quoted context omitted.

I know it used to be, but is it really still common for embedded systems to use weird architectures that G++/Clang don't support?

Unless it is a popular system or common architecture, yes.

> is it common for weird architectures to exist?

> yes, unless you're using a common one.

Re: I write type-safe generic data structures in C

#113
Welcome to around 1992, when Borland published BIDS 1.0 using similar tricks, as C++ templates were yet to be made part of the language.

With similar articles in The C/C++ Users Journal and Dr Dobbs, throught their existence.

While the effort is commendable, maybe pick a safer language that actually has all the features for type safe generic code.

Re: I write type-safe generic data structures in C

#114
post #86

Earlier quoted context omitted.

Why would you write C++ if you can get the same result by jumping through a few hoops with C?

Templates in C++ require language support - you can't simply implement them with "a few hoops" in C.

Templates are a solution for a problem that c++ themselves created

Re: I write type-safe generic data structures in C

#115
post #107

Earlier quoted context omitted.

In what situation fn() doesn't mean fn(void) under C23?

None, but that is not my point. Before C23, fn() already meant the same thing as fn(void) in function definitions , which the situation under discussion here. C23 changed what fn() means outside a function definition.

Oh, yeah, the codegen for the fn() itself would likely be the same, but the prototype of that definition is still a K&R function. https://godbolt.org/z/Psvae55Pr

Re: I write type-safe generic data structures in C

#117
post #86

Earlier quoted context omitted.

Templates in C++ require language support - you can't simply implement them with "a few hoops" in C.

Templates are a solution for a problem that c++ themselves created

You mean the same problem that the article is trying to solve in C? Generic data structures?

Re: I write type-safe generic data structures in C

#118
post #45

Earlier quoted context omitted.

> it should be `int main() { List(Foo) foo_list = {NULL};` In C `int main()` means the function takes an unknown number of arguments. You need `int main(void)` to mean it doesn't take any arguments. This is a fact frequently forgotten by those who write C++.

This is incorrect. In a function definition, an empty list means it takes no parameters. 6.7.5.3 Function declarators > 14. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.

"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 parameter and argument.

https://stackoverflow.com/questions/156767/whats-the-differe...

Re: I write type-safe generic data structures in C

#119
post #60

Earlier quoted context omitted.

i am firmly of the opinion that compiling to c is a better route than doing clever c tricks to sort of get what you want. the compiler can be pretty minimal and as you note it pays for itself.

There’s some prior work called CFront. It implements a superset of C that’s just an “increment”. I think it’s worth looking into, it might take off one day!

Here I've got it to work with recent compilers/OSs https://github.com/mingodad/cfront-3
Post reply on HN