Using Lint with Arduino code

Have any of you used Lint/PCLint with Arduino code?

Is it applicable for embedded use?

Never discussed as far as I know.

Why do you want to use lint?

I just hit the compile button and fix the first error, and check if there are obvious ones left, fix them too.
Then hit the compile button again. And if it compiles completely I hit the upload .
I dive only into non obvious errors if they are the first one. (once the compiler is of track you should take its output not too serious :wink:

by using decomposition of the problem the number of compiles is quite low.

and then there are the semantic errors like wrong formulas etc ... :wink:

robtillaart:
Never discussed as far as I know.

Why do you want to use lint?

Do you know what Lint is and what it is used for?

Do you know what Lint is and what it is used for?

Yes, it is one of the static code analysis tools checking style, common syntax problems etc. Used it quite extensively in the days when C was young and compiling code tooks substantially more time than these days.

so, Why do you want to use lint?

Why would someone want to use lint?

To enforce a good coding style and check for common syntax problems as stated in the previous answer. Its good practice to use one and so the OP has a valid question, can lint (or an equivalent) be used on Arduino code.

Five years and seven months.
Must be a new record.

My experience has been that Lint was mostly used to encourage compliance with a coding style. Mostly this had to do with making sure parameters were strongly typed and matched the declarations. Things like gotos or type casting were frowned upon. This is used to save the programmer from himself. In general, I think it is a good idea. Depending on the values of the Lint program.

If it is used to point out potential problems like if (val = 0); then it could save some debugging time. However, I found that usually the personal values of the proponents were more in line with making the code more maintainable. Which usually meant sacrificing size and speed for understandability. For example, some of the newer and more popular languages allow you to use Strings as indices into an "array". This is an easy thing to understand and makes a lot of sense from some programming points of view. The compiler builds a hash table or something behind the scenes and the programmer doesn't have to worry about how it is implemented. But compared to a simple scaler array, it takes up way more memory and is orders of magnitude slower. Generally, processors are fast enough now, and RAM is cheap enough that nobody cares. But I wouldn't think of doing something like that on an Arduino Uno. I even shy away from any Strings. My values are different. I prefer to have more control over the code that gets generated, and I like things to work. And to be fast and small and efficient and effective.

The really nice thing about Lint is that it doesn't really enforce anything. It just makes suggestions and tells me when I do something that could be a problem. Then I can decide whether that really was a bad idea and I should fix it, or if I meant to do it that way and can ignore it.

Sometimes I wish there were a Lint type program written especially for Arduino programs. It could have warnings like

  • code not auto-formatted (or formatted at all)
  • excessive use of delay() function
  • integer constant used when byte would do
  • integer used to store millis() -- should be unsigned long
  • INPUT_PULLUP used and then digitalRead(pin) checked for HIGH
  • variable used in interrupt service routine not declared volatile

That could have some possibilities.

My company produced a C compiler for MSDOS years ago. It had a "picky flag" which you could set between 1 and 10. Most people used the default setting of 4 and, perhaps, dialed it up to a higher value when they wanted to generate production test code. We never saw any non-trivial published code that passed level 10. As such, it's Lint-like capabilities actually got in the way of code development. I don't remember an example of a level 10 error/warning, but level 7 jumped all over you if you did a printf() without doing something with the return value from the call.

Lint has its purposes, but it can also get in your way.

I don't remember an example of a level 10 error/warning, but level 7 jumped all over you if you did a printf() without doing something with the return value from the call.

Amen to that - I recall using a commercial package I once used littered with (void)printf("blah blah");
Drove me mad. Which explains much about my present demeanour.

AWOL:
Must be a new record.

Would be a mildly entertaining SQL query: What is the greatest delta between two posts on one thread?

Five years and seven months.

I typically wonder two things: 1. How does the person find posts / threads that old? 2. Why does the warning (see below) in red text not dissuade the person?

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

In any case, welcome to the forum @marktyers.