News for hackers. Stuff that matters.

unusualcool

What's your opinion on adding generic functions (parametric polymorphism) in C?

I'm working on a research project about C and, at the moment, I'm investigating the possibility of introducing/proposing generic functions (and parametric polymorphism) to the language. I can't yet provide any technicalities, but the idea is to have a design along with C style/look-and-feel — think of it more as an extension to C11's `_Generic', than of C++ templates.The project motivation is...

( Read More... | no comments | 2 points | on HN )

A (backtracking-aware) parsing table for expressions of the C language

This is a table I created to aid me during a rewrite of the Psyche-C project's parser (and underlying grammar). I'm not sure whether the table's "encoding" will be clear to everyone, though — if not, please comment on the document. Another reason for this post is to invite you to check out the project's website (the link is on the document) for it's being renewed. From a usability standpoint,...

( Read More... | no comments | 3 points | on HN )
Re:Generics in C without void* or macros – enabled by psychec on Monday September 09, 2019 @12:47PM (#20919821)
Sorry, it wasn't my intention to be tricky, that's why I added "enabled by psychec" to the subject line. I hope that, once landing at the project page, it should be obvious that such functionality is provided by a tool.
Re:Generics in C without void* or macros – enabled by psychec on Monday September 09, 2019 @12:36PM (#20919707)
This needs to be made clearer in the readme: C++ and Haskell are requirements for building the type inference engine; Python is necessary for invoking the frontend (or the binaries can be downloaded).
Exactly. Some programs are inherently ambiguous. In such cases, we cannot do much. - Example 1: `void f(){x * y;}` It's impossible to know whether that is a multiplication or pointer declaration. - Example 2: `void f(){x y = 0;}` We can only know that x is a scalar type (in C terminology), but it could be an int, int * , int * * , etc.
Yes, a few IDEs perform some disambiguation during parse. But notice that the ability to deal with ambiguities and to come up with a proper AST is just step 0 of the pipeline. The challenging part is type inference - as far as I know there are no other tools that can reconstruct sources as we do.
You're right, it's not always used. Please notice my other answer above, the project is still a prototype. Eventually, we'll filter what actually goes to the generated header and we'll allow the user to specify whether he/she wants bools, inference of C/POSIX library functions, etc.
Indeed, this can be an arguable choice. But notice the project is still in research, it's not an end-user product yet. Eventually, we'll offer options so the user can specifier whether he/she wants such a thing (or inference of standard/posix library functions, for example).