r/ProgrammingLanguages • u/P-39_Airacobra • Jul 27 '26
Discussion A hole in systems programming language design
Given the recent discourse about systems programming I wanted to throw my 2 cents in. This may be a controversial take in a subreddit that's all about innovation and improvement, but I think a lot of budding systems languages are trying too hard to "fix C" and this is exactly why C has not been replaced yet.
Like it or not, C is successful. It does what it means to do very well. Yes, it bites you constantly, but developers have made some form of peace with this because they appreciate the essence of the language. Systems programming is a very pragmatic field, and what works, works.
A lot of language designers want to improve on C, when by nature to "improve on" C is to depart from it, because C is less about what it includes and more about what it omits and what it lets you do that other languages don't.
If you want to replace C, you need to just make C but without the pain points. Less undefined behavior, more standard compiler behavior, easier function pointer syntax, safer macro system, etc. The things that C can't do because of backwards compat.
On the other hand, bolting on features, revamping C's core nature, aren't going to give you a language that will replace C at the low-level or among hobbyist programmers. Most developers aren't as concerned about what C lets them accomplish, as they are concerned about all the painful tedious tendencies of the language.
View all comments
Show parent comment
1
u/EggplantExtra4946 Aug 02 '26 edited Aug 02 '26
Let me just say that the main application I imagine is for read-only introspection purposes, but if you wanted to modify a value for whatever reason, if it's typed it's typed, there shouldn't be a typing issue if you overwrote a variable on the stack, be it a uint64_t used as an iteration variable in a for loop or a pointer to a data structure, however there would be a good chance of introducing a bug because the compiler might keep the same variable in a register and assume that the one on the stack is the same value.
I see what you mean but given that the only use cases I think of is to dump the stack trace or debugging, NOT for say returning a value to the caller for example, there wouldn't be too many use cases for that especially when considering that you don't know who your caller is so what would be the intent? In any case it's not a typing issue.
Even then, if you implemented that in a language with separate compilation the stack frame's type would have to be inserted in the object file as reflection data (that is read-only), so the stack slot offsets of specific a priori know local variables would only be know at runtime and their types would be dependent of the the value describing the type of the struct/union field in the reflection static data, which would require some kind of dependent/refined type for static typing guarantees to be maintained. So your dispatch would only depend on the set of possibele types, not on the set of possible callers.
If for example you would like to override a specific local variable included in all callers with the same type and the same meaning/use case, maybe a value passed as argument to the current function, or a dynamically (in effect) scoped variable like a pointer to an allocator, then it's only the stack slot offset (offset to rbp) that would be unknown and all you'd have to do is locate it in the reflection data (if the type uniquely used in the caller like an allocator, otherwise you might need the identifier as well, assuming it's the same in the callers but if not you no longer have a common knowledge of all callers for that specific use case), but then you'd be able to use a single memory computed using the stack slot offset only known at runtime to overwrite it. If you'd use a raw pointer in the program (because I have no idea whiat higher level type could do the job), the address could be constrained to be == to RBP of the caller + whatever offset you read in the reflection data at the entry describing the local variable you want to overwrite.
But what commonality though and for what intent?
Really? I've heard that ""conservative"" garbage collector look like for values that "look like pointers". But otherwise, for a time I was designing a bytecode VM for a statically typed language with a precise GC and I concluded that when the GC has identified the function of a given stack frame though the tag inside the stack frame, all the GC has to know is which stack slots contain a pointer to a GC allocated object, the other ones containing unboxed numbers.