Skip to main content
DJC
Senior
Nov 18, 2020 10:37 AM UTC
Solved

How to enforce a coding standard in STMIDE ?

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.
Ozone
OzoneBest answer
Principal
Nov 18, 2020 12:37 PM UTC

"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
Nov 18, 2020 12:37 PM UTC

"Coding standards" are totally arbitrary.

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

Otherwise, you can do code reviews.

TDK
Nov 18, 2020 10:53 PM UTC

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
Nov 19, 2020 8:41 AM UTC

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
Nov 19, 2020 1:48 PM UTC
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""."