Skip to main content
DJC
Senior
November 18, 2020
Solved

How to enforce a coding standard in STMIDE ?

  • November 18, 2020
  • 5 replies
  • 1555 views

Is there a way to enforce a coding standard in STMIDE with some text highlighting?

i.e: "function names should be Function_Name()" etc.

What rules does STM use for their generated libraries in this case?

Does anyone recommend some plugins for this? 

What standards are others trying to follow when writing their code?

This topic has been closed for replies.
Best answer by Ozone

"Coding standards" are totally arbitrary.

You can enforce rules like MISRA through integrating PCLint (or similar tools).

Otherwise, you can do code reviews.

5 replies

Ozone
OzoneBest answer
Principal
November 18, 2020

"Coding standards" are totally arbitrary.

You can enforce rules like MISRA through integrating PCLint (or similar tools).

Otherwise, you can do code reviews.

TDK
November 18, 2020

There is no standard for enforcing coding standard in C or C++, partly because the language is 30+ years old and existing code out there.

Eclipse (which STM32CubeIDE is build from) can auto-format things. I find that helps quite a bit when importing messy/outside code.

Window -> Preferences -> C/C++ -> Code Style -> Formatter

Auto-formatting can be done with Source -> Format.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DJC
DJCAuthor
Senior
November 19, 2020

Handy! Thanks!

Based on this, it looks like the Code Gen is done with the formatter set to GNU. However when one installs STMIDE, the formatter is set to K&R by default.

Not a big deal, but I do bet a bunch of people get a bit OCD when they press tab in main.c and it tabs out to a different place that what is already written.

TDK
November 19, 2020
Based on the code pasted into the forum by users, I would be surprised if more than 20% of programmers enforced any type of style at all.
"If you feel a post has answered your question, please click ""Accept as Solution""."