16 votes

Making C less dangerous

6 comments

  1. [6]
    teaearlgraycold Link
    I think the real solution is to stop using C - or at least limit its use. For existing projects it may be better to write new modules in a safer language that has good interoperability with C.

    I think the real solution is to stop using C - or at least limit its use. For existing projects it may be better to write new modules in a safer language that has good interoperability with C.

    9 votes
    1. [5]
      mironimous Link Parent
      One of the great points of C is that it is widely available on many architecture - if the ISA exists, there is a great chance someone wrote a C compiler for it, and that's partly why Linux is...

      One of the great points of C is that it is widely available on many architecture - if the ISA exists, there is a great chance someone wrote a C compiler for it, and that's partly why Linux is written in C (looking at the wikipedia page, it supports at least 30 architectures).
      A further problem is that llvm, which is used by quite a lot of safer languages, is not really a good fit for 8-bit microcontrollers like 8051, 6502 or z80 and no one would be willing to write a rust compiler specifically for 8051.
      Of course it is a good idea to use safer languages for systems that have hundreds of MBs, but there are at least 2 8051s inside my mouse alone and my e-piano runs on an SH-2a (and it has wlan functionality, so security is definitely an issue), so it doesn't seem like we will be able to stop using C soon.

      12 votes
      1. [4]
        s4b3r6 Link Parent
        You might be surprised. The avr-rust project is under active development, and is getting close to useable. Well, useable for hobbyist, but not ready for production yet. Some architectures will...

        no one would be willing to write a rust compiler specifically for 8051.

        You might be surprised. The avr-rust project is under active development, and is getting close to useable. Well, useable for hobbyist, but not ready for production yet.

        Some architectures will miss out... But where interest lies, new ones will appear.

        (8051 specific - there's a couple assemblers written in Rust, which can be useful, but far less.)

        However, C runs everywhere, like you said. And I don't see that changing any time soon.

        6 votes
        1. [2]
          ReBurn Link Parent
          The problem there is that compilers for those microcontroller configurations tend to only remain usable for hobbyists as its hobbyists creating them. They are fun to play with, but I'd be weary of...

          The problem there is that compilers for those microcontroller configurations tend to only remain usable for hobbyists as its hobbyists creating them. They are fun to play with, but I'd be weary of using that kind of compiler for any consumer application.

          5 votes
          1. s4b3r6 Link Parent
            Usually I would agree, but that isn't the case with avr-rust, the exception to the rule, if you will. It's being maintained by Dylan McKay, as is it's parent project, LLVM-AVR. He's a student, and...

            Usually I would agree, but that isn't the case with avr-rust, the exception to the rule, if you will.

            It's being maintained by Dylan McKay, as is it's parent project, LLVM-AVR. He's a student, and the hobbyist, though he has also worked with Adafruit, and has made some sizeable contributions to mainline LLVM. However it has major contributions from Alex Crichton (Mozilla), and Steve Klabnik (Mozilla). Klabnik has suggested on occasion he would step in to save the project if McKay was unable to continue supporting it.

            6 votes
        2. mironimous Link Parent
          Surprising indeed. I've seen once tried to use an experimental llvm z80 backend (which threw errors on half of my code), but I didn't know there was an avr backend in the official llvm tree....

          Surprising indeed.
          I've seen once tried to use an experimental llvm z80 backend (which threw errors on half of my code), but I didn't know there was an avr backend in the official llvm tree. That's probably because my only avr experience amounts to getting a loudspeaker to play some square tones on an arduino.
          I will also look into the rust 8051 assemblers, I'm normally using the good old asem-51.

          1 vote