Better HN
topnewbestaskshowjobs
Log inSign up

uecker

2,488 karma · joined Apr 14, 2020 (6y ago) · 2,122 submissions

Computational Magnetic Resonance Imaging, Real-time Magnetic Resonance Imaging, GCC Contributor, BART Toolbox, Member of ISO C WG14
Submissions

comment 55m ago · link · parent

There is a huge different between having to actively explore all variables to find out what is behind them to simple looking at the code.

comment 1h ago · link · parent

I use slices in C, I just have to define them myself.

comment 16h ago · link · parent

That is fair, but we are a bit in a different situation. There are many C compilers, and we can not unbless language constructs every time one of them has implementation bugs. Perhaps would could this in this case, but compared to other issues compilers have, it is also a relatively minor issue in terms of practical impact on C code.

Also to be fair, it has to be said that officially blessed safe Rust code is not really what is competing with C.

comment 1d ago · link · parent

If you decided that this is what you want to believe, I guess no argument will convince you. But note that I was programming in C++ before switching (almost) fully to C, and I am telling you that I prefer writing C - by a lot!

comment 1d ago · link · parent

It is not trivial for anything to be done in a committee. If we wrote this text today, we would clearly specify this differently, but in the 90s there was not much reason to assume that this will be misunderstood. Note also that the far / near pointer model used by segmented architectures was never part of ISO C.

The committee wanted to have TS 6010 which would clarify that this work, but at the request of compiler vendors it is not (yet) part of the IS. But the reasons are unrelated to pointer round trips.

comment 1d ago · link · parent

No, not really. There are couple of smaller compiler projects such as tcc, slimcc, cparser, kefir, etc. that I kind of hope will mature a bit more, but I haven't really used them.

Sometimes I am wondering whether I should continue to develop my own compiler with an eye towards correctness, but I do not have enough time at the moment. And fixing bugs in GCC seems more useful.

comment 1d ago · link · parent

This is where I disagree. In the context when this was written, I think it was clear that two pointers that compare equally were meant to be interchangeable.

comment 1d ago · link · parent

There are stricter requirements for casting a void pointer to (u)intptr_t and back. Again, a segmented architecture should not provide (u)intptr_t. But if an implementation has it, in my opinion, this is expected to work.

comment 1d ago · link · parent

Perhaps. In C one should avoid any non-local use of one-after pointers and any integer-to-pointers casts. Then I think one is also safe from miscompilation. Alternatively, one can use a compiler that is not broken.

comment 1d ago · link · parent

The standard is English text which may not alway be perfectly precise, but the wording there clearly was meant to allow this.

comment 1d ago · link · parent

Hey, that's me. TS 6010 is not currently supported by GCC and Clang. But also for Rust this does not work due to the same compiler issues. (as you point out)

comment 1d ago · link · parent

I hear this claim sometimes, but I think this is a far-fetched interpretation that you can only compare the pointers after backconversion but not use them.

A segmented architecture that can not support this should not support intptr_t. It is optional for this reason.

comment 1d ago · link · parent

References hide important semantic information:

    int x = 1;
    foo(x);  
    // What values has x?
In C the answer is obvious, in C++ due to the existence of references and the poor way they are designed, it is not anymore.

comment 1d ago · link · parent

Actually, those are things I like about C:

- It does not run code behind my back when I access a field.

- I see when a pointer is used, so the syntactic distinction between -> and . is important.

Being able to change this without changing these little things is far less important to me than being able to understand important properties of the code just by looking at it.

comment 1d ago · link · parent

Before you said "impossible", now you merely claim the language "fights" you. But I do not see how the language fights me, it is trivial and convenient for me to write abstractions in C, including polymorphic types. In fact, I find it far more enjoyable to write C than C++.

Those types can be written in a way that C's type system checks type safety, and my example was of this kind. No "pinky promises" necessary. In fact, these types are very similar to templates in C++. I would even agree that there are bad, but just in the same way templates in C++ are also bad.

And finally: you can also write a sort that inlines its comparator in C as well.

comment 1d ago · link · parent

I agree that C should be stable, but my point was also not that it should change a lot. As one can see with Fil-C or with model checkers proving memory safety, a lot can be done even without changing it. Although Zig is nice, I really prefer C.

comment 1d ago · link · parent

I agree with this. And C could certainly be much further, if we only had a fraction of the resources the industry spend on C++ or Rust.

comment 1d ago · link · parent

You are switching topics to polymorphic types. But you can also implement them in C in a type safe way without void pointers.

Here is an example for a generic vector type: https://godbolt.org/z/7MdGqcdbq

Your mistake is believing that you need native syntax for such feature to be possible. But this is not true.

comment 2d ago · link · parent

You can build types around structures and access them via wrappers. This works perfectly fine for many abstractions. Sure, one can break those abstractions, but not accidentally, and this is true also in other languages.

Update: In fact, you can also build quite reliable abstractions around incomplete structure types. Those abstractions are better than what C++ adds, where the abstractions in the header are all very fragile.

comment 2d ago · link · parent

I found that you can not build good abstractions in C is mostly a myth.

comment 2d ago · link · parent

It is very easy to add one yourself though.

https://uecker.codeberg.page/2026-10-24.html

comment 2d ago · link · parent

The simplest way to show this is that the adjoint (complex transpose) DFT matrix is the inverse, so U^H U = I.

(For DFT there are different scaling conventions which may be taken into account.)

comment 2d ago · link · parent

While this is true, I don't think this is really the full story even with regard to memory safety. And then Rust makes it easier to make it harder for distributions to roll out security updates, and it also makes it easier to create supply chain issues.

comment 3d ago · link · parent

And yet, for any of those, the C world still get "why do we still use this language?" comments.

comment 4d ago · link · parent

The way to deal with APIs which use size_t and which works for me is to convert at the last moment.

comment 4d ago · link · parent

The N >= 0 check you often get automatically using sanitizers, e.g. when using an array [N] somewhere, or by concerting to size_t at last moment and then getting a size which is so big that allocation is guaranteed to fail.

Not that are wraparound CVEs in Rust as well, so there is no perfect solution even outside of C.

comment 4d ago · link · parent

It is also easy to write it wrong in other languages. The coreutils rewrite had hundreds of issues, cloudflare brought down half of the internet because in the magic language where nothing can go wrong due to the advanced type system someone used an unchecked .unwrap (but this does not count, because this was Rust and not C - so could not possibly be the fault of the language, so only the programmer is to blame), and just recently Microsoft found a couple of memory safety issues in Rust's standard library. And let's better not talk about the supply chain.

comment 4d ago · link · parent

A crypto library written in Rust would not be available everywhere, so can not be the only one. And if you formally verify the code, you can also formally verify that it is memory safe, so there is not much point to have it in Rust. Crypto has properties which may be difficult to verify though.

If you want a safe interface that does not require passing random sizes around in extra arguments, this can also be done in C.

comment 4d ago · link · parent

One can abstract buffer handling away in C just fine, eliminating all those problems. I don't know why programmers insist on open-coding low-level buffer management.

comment 4d ago · link · parent

Why unrealistic? I was in the unsigned camp a long time ago and switched to signed types for indexing and sizes, and this made many problems go a way.

There was just a nginx issue that highlights how problematic the use of unsigned is in this context: CVE -2026-123007

12345
71