For the best experience on desktop, install the Chrome extension to track your reading on news.ycombinator.com
Hacker Newsnew | past | comments | ask | show | jobs | submit | history | more thradams's commentsregister

"uninitialized memory" and "null checks" is part of flow analysis. UB and out of bound is not part of it.


The answer you can have the same source code and compile with gcc, but only cake is implementing the checks at this moment. The have the same source code compiling in any compiler a header ownership.h is used to define owner etc as empty macro. This strategy is used on cake source itself, that is checked with cake, but compiled with gcc msvc and clang.


Got it, thank you!


Cake is a C23 front end, but it can also be used as a static analysis tool. The qualifiers can be empty macros then the same code can be compiled with gcc , clang and the static analysis of ownership can be using cake.

Inside visual studio for instance, we can have on external tools

C:\Program Files (x86)\cake\cake.exe $(ItemPath) -msvc-output -no-output -analyze -nullchecks

The main annotations are qualifiers (similar to const). C23 attributes were considered instead of qualifiers, but qualifiers have better integration with the type system. In any case, macros are used to be declared as empty when necessary.

The qualifiers and the rules can be applied to any compiler. Something harder to specify (but not impossible) is the flow analysis.

Sample of rule for compilers.

int * owner a; int * b; a = b;

we cannot assign view to an owner object. this kind of rule does not require flow analysis.


Cake is a C23 Front End http://thradams.com/cake/index.html that is implementing static ownership checks.

Cake source itself is already using this feature that can be used and disabled with few macros.

The link is a tour explaining the concepts and usage of this feature.


I am currently experimenting with static ownership checks for C, aiming to provide guarantees that resources are released when necessary.

As this is a work in progress, bugs are expected. More flow analysis is required.

Despite that, you can still try out the checks online and observe some helpful error messages.

Simply visit the website below and select the 'Extension - Ownership' samples.

http://thradams.com/cake/playground.html

The C type system was extended with some new qualifiers. But only with flow analysis is possible to understand when variables goes out of scope or understand when the variables have been move before the end of scope. As I said, this is a work in progress but I am already very optimistic.


To remove comments from source all you need is a tokenizer. You don't need all the tokens, just the "preprocessor tokens". For instance literal strings, ppnumbers ... Then /comments/ can be replaced with 1 space and //comments by \n


Multi-line comments would need to be turned into multiple blank lines, but yes, thank you for pointing out that I've been over-thinking this. I will look into what is the path of least resistance for this tokenizer-based transformation.


My goal with the transpiler is not only the transpiler, although my front end had to be created differently of an normal compiler and preserve more tokens that could be discarded during the compilation. This also can be useful for a tool that does refactoring.. like renaming variables etc.. so in any case it it useful.

The new C23 language has a lot of features that makes your code not compile in previous C versions like attributes digit separators etc.. Someone may wants to create a new project in C23 and soon regret because the users of the code may need C99. This would be one use case, you can create a C23 code and have C99 versions of the same base code.

Unfortunately my transpiler is not "production ready" yet and I don't have IDE plugins etc.. that is required to make the tool more productive.

The other advantage, if we had a production ready transpiler with a IDE support etc.. it that we could use C23 and compile to C99 without having to wait for compilers like msvc to implements the standards.

Also some experimental features (like defer) can be used and you can distribute your code in standard C99. We have more freedom to use wherever we want and distribute a "readable" C99 code.

By the way most of the C transpilers or compilers generates C code only for immediate compilation. CFront was like that.

My transpiler have two modes one is for direct compilation and other is to distribute generated code.

Each mode has advantages and disadvantages.


> The new C23 language has a lot of features that makes your code not compile in previous C versions like attributes digit separators etc.. Someone may wants to create a new project in C23 and soon regret because the users of the code may need C99.

Ah. I was not aware of this.


It's a front end. The backend implemented generates C code. I hope to have other backends in the future.


The part that is the "transpiler" is visit.c and visit.h.

You can use it as reference to create different "visits". For instance, I am implementing a code format at "visitformat.c".

I have implemented a "naming convention checker" inside the parser, but it also can be a "visit".

Static analysis etc..can be a visit.

Inside the visit context you will find

struct ast ast;

That is the AST.

I would say the syntactic analysis parser is 100% complete C23.

Semantic analysis that is not 100%.


Everything that is not part of C23 I annotated with "extension". For instance "Extension Defer" or "Extension Lambda" are not part of C23.


Iirc NarcissiusJS was a test-bed for future JS features at a time when development was a bit slow that allowed quick prototypes.

https://github.com/mozilla/narcissus https://wiki.mozilla.org/Narcissus


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search:

HN For You