by pjmlp · 12y ago · 0 comments
I'm curious, why do you say "safer"? These are languages for microcontroller programming. The things you do there are bound to be "unsafe", like peeking and poking memory for memory mapped i/o and disabling/enabling interrupts.
Unless, of course, all the possible things (i/o, timers, interrupts, etc) are wrapped in some kind of "safe" api so you essentially don't have access to low level facilities any more. The Arduino programming environment is kinda like this but you can still cause bad things to happen and if all else fails, hang the device with an infinite loop.
Is there any backing for such claims of "safety"?
There are things which are inherently safe by design in languages like Pascal -- e.g. in a naively-written program you can't write past the boundary of the UART RX buffer and thrash some other array in your program -- but your observation is fair.
Which, of course, you can accomplish in C by wrapping your UART buffer handling code in functions that do bounds checking. And I assume that a micro controller Pascal or Basic dialect will have some kind of peek/poke from/to arbitrary memory addresses that can be misused just as a pointer access in C.
Safety is hard to quantify and measure and calling one language safer than another sounds more like an opinion than a factual claim, especially in this context.
Of course, and you pay other hefty prices in Pascal or Basic for getting this sort of stuff "out of the box". Pascal isn't my favourite systems programming language, either :-).
See http://static.rust-lang.org/doc/master/rust.html#unsafety
Nothing new in software development. All the "new" shinies are decades (!) old.
1. Performance reasons. For example: zero copy data structures, mutable data structures, controlling data locality.
2. Direct memory mapped hardware access. For example: device drivers, kernel, embedded systems, microcontrollers.
3. Bitwise and machine specific conversions. For example: endianess conversions.
4. Structure type coercion. For example: object systems, tagged data structures etc.
Whereas in C there is no way to distinguish between unsafe and safe code.
Of course doing this usually means your code isn't portable, sometimes not even to other versions of the same compiler. I often wish C had a defined order for bitfields, for example.
One of the things I do to help debug & test embedded code is to factor out code which isn't dependent on the hardware platform (eg communication protocols) into a library, and compile it for, and write test programs to test them on, the host. So even embedded code is often best written to be as portable as possible.
If you are going to invoke the usual C FUD about bounds checking and such, you can disable them on parts where performance REALLY matters.
Plus all compilers share the same backend.