6 ms·
> Most of what gives high-reliability or high-assurance code that label is the process rather than the language. This is what I've heard too. I have a friend w
by smj-edison 1y ago
> Most of what gives high-reliability or high-assurance code that label is the process rather than the language.
This is what I've heard too. I have a friend who works in aerospace programming, and the type of C he writes is very different. No dynamic memory, no pointer math, constant CRC checks, and other things. Plus the tooling he has access to also assists with hitting realtime deadlines, JTAG debugging, and other things.
- 1718627440 1y ago> no pointer math How does that work out? Does he never uses arrays and strings?
- pjmlp 1y agoLike in most languages, with indexes.
- sgsjchs 1y agoBut in C that's just syntax sugar for pointer math.
- pjmlp 1y agoExcept it is more obvious what is the intention, it is about clarity to the reader.
- 1718627440 1y agoMy point was indeed, that if you don't use pointer arithmetic in C, that means that you don't use arrays. I mean when you declare arrays of a fixed size, you can also declare an equivalent number of primitive variables instead, but I would find that inconvenient. Hence the question.
- smj-edison 1y agoIf I remember correctly, he meant that only array accesses are used, because their length can be checked (as all arrays have a static length due to no dynamic memory).
- uecker 1y agoIndeed, this is what many people do. But even if you use dynamic memory, if you replace pointer arithmetic by array indexing, you get bounds checking. And in C this also works for arrays of run-time length.
- 1718627440 1y agoBut can't I put any pointer arithmetic in array brackets, so it wouldn't limit anything?
- uecker 1y agoWhatever index you compute can be checked against a bound.
- 1718627440 1y ago2[a*b] What bound?
- uecker 1y agoThis does not even compile. For array indexing, array[expression] if "array" has a bound whatever expression evaluates to can be checked against the bound of array. If "array" is not a bounded array but a pointer or an unbounded array, then this does not work, but my point is that it is easy to avoid such code.
- deleted 1y ago[deleted]
- uecker 1y agoIt still makes it possible to have bounds checking. (And it is also not true anymore for C2Y.)