Recommendations for MISRA-C encoding for personal programs?

I usually work as a tree and not as a developer. I'm learning C / C ++ for embedded systems, trying to make some of my tools standalone to save many hours of rework.

At this point, fun and well, I've spent maybe a hundred hours coding / learning and already saved more time *.

How do I want to keep buying and follow the MISRA coding rule of "must-have good idea"? What does MISRA contain? Just coding rules or tips to make it more secure?

These tools can be dangerous (because they cut wood, and the human body is much less stable ...).

Note. I am obviously doing my test in 4 steps:

  • Just pic works with OSD and SD card logger (one day I'll make anylze tool and stop reading).

  • I connect the instrument without anything

  • I use soft foam drills / cutters

  • I am doing a real long distance test with my hand with an emergency stop button.

Also, I am the only employee and no one else has access to my workplace.

* while I turn the drill into a kind of 3D wood receiver (doing the imprecise part of the job) and the "cutting board" into an automated one.

Note2: I am not a native speaker, so the instrument names are probably disabled.

+3


source to share


2 answers


MISRA is designed for use in the automotive industry, although it has grown significantly at this stage. The aim of the MISRA recommendations is:

  • Security
  • Ensure software reliability, reliability.
  • Human safety should take precedence in the event of a conflict with property safety.
  • Consider both random and systematic failures in system design.
  • Demonstrate reliability, not just rely on zero failures.
  • Application of safety considerations in the design, manufacture, operation, maintenance and disposal of products.

The docs mainly consist of rule-based advisory information for code that attempts to satisfy these goals. Over the years, prices for MISRA documents have dropped slightly, some documents can be bought online from MISRA for as little as GBP 10 + VAT.



However, as a beginner and hobbyist coder, I would suggest strengthening your knowledge of C and C ++ first. While it is often good practice in most industries to follow an appropriate standard, if applicable, documents are written with the assumption that the reader has a very solid foundation for the languages, and with regard to the issues and processes governing the full commercial type of application written in them. If your seminar is for personal use only and depending on the workplace safety regulations in your jurisdiction, I can say that a good knowledge of languages, language tools and hardware will allow you to start making the right choices about how more code than reading MISRA at this stage.

As noted above, and bears repeating, MISRA is not some magic wand or a specific way to get around things that ensure your code is good, working, and safe. Good and bad code can be standards compliant. Following MISRA, before you have a good and complete idea of ​​what you are doing, it can be as much as ensuring that every cable in your workshop is neatly fastened in place and then pounded by a chisel.

+4


source


MISRA-C is a set of rules that will allow you to get rid of known problems and ill-defined behavior from a C program. It is a "safe subset" of C, forbidding various forms of unsafe practices through rules that target known bugs, such as dependence on ill-defined behavior or implicit conversions. The advantage of C is that it is a very old language, which means that all language flaws are well known.

MISRA-C focuses heavily on analyzing static code to find compile-time errors. This is something to keep in mind as, to my knowledge, there are no open source static code analyzer tools that can check for MISRA-C compliance. Commercial tools tend to be very expensive and often full of errors / false positives as well. However, most of them are useful.

MISRA-C is focused only on C programming, it does not address issues with the processor or microcontroller, etc., although it enforces some form of defensive programming that is anti-EMI, startup code and other forms of unexpected program behavior. (For a list of general tips and tricks outside of C, see this . Not all of them necessarily apply to your particular machine.)

To demonstrate MISRA compliance, you create a "match matrix" that shows how you will catch each directive / rule of a MISRA-C document: through compiler messages, peer review, static code analysis, etc.



Most of the rules in the document make a lot of sense, but some don't. However, MISRA-C allows deviations from most of the rules, considering them one of the following:

  • Mandatory. Deviations are not allowed.
  • Recommended. A formal rejection procedure must be called if the rule is not followed.
  • Advisory. You can deviate from the rule without formal deviation.

Typically, the creation of MISRA-C compliance is thus accomplished by establishing a company coding standard that takes all the rules into account. The easiest way to implement it is that this document records which rules are followed and which ones are skipped at the company level. Then set static code analysis filters accordingly.

+2


source







All Articles