Any C/C++ LINT type checking recomendations

G

Greg Roberts

We have a large code base, mainly C but with some C++ which we wish to check
for
existing issues in an effort to be proactive.

I have downloaded the open source GLINT program but am having big problems
trying to get it to run.

I will be looking at PC-Lint at http://www.gimpel.com/

Does anyone have any other recommendations, it can be commercial s/w for
this ?
Also Perl scripts would be good as well to run over the source as an
alternative.

Many thanks
 
W

Wolfgang Kaufmann

* Thus spoke Greg Roberts <[email protected]>:

Hallo,
We have a large code base, mainly C but with some C++ which we wish to
check for existing issues in an effort to be proactive.
I have downloaded the open source GLINT program but am having big problems
trying to get it to run.

glint?

$ man glint

| NAME
| glint - GLINT/Permedia video driver

Do you mean splint? Splint doesn't work with C++ code, see
I will be looking at PC-Lint at http://www.gimpel.com/

Afaik its the best lint (for C and C++ code) out there.


[f'up2 -> poster]

Wolfgang.
 
C

CBFalconer

Greg said:
We have a large code base, mainly C but with some C++ which we
wish to check for existing issues in an effort to be proactive.

I have downloaded the open source GLINT program but am having
big problems trying to get it to run.

I will be looking at PC-Lint at http://www.gimpel.com/

Does anyone have any other recommendations, it can be
commercial s/w for this ? Also Perl scripts would be good as
well to run over the source as an alternative.

Don't know about GLINT. SPLINT is free and good, but only handles
C. PC-Lint will cost you about $200 (US) and will handle C++ and
C.

Turning these things loose on an existing code is likely to be
unproductive, especially if it is a large code base, because of
the volume of nits to pick. Use on new modules will be very
productive.

Congratulations. This is the first legitimate c.l.c c.l.c++
crosspost I have seen.
 
A

August Derleth

Greg said:
We have a large code base, mainly C but with some C++ which we wish to check
for
existing issues in an effort to be proactive.

lint and lint-like programs are annoying to the point of uselessness.
They consistently warn about things that /are not wrong/, /never have
been wrong/, and /are not even dangerous/. There's one example that
sticks out in my mind:

int x = 1;

/* code */

if (x) return y;

will /always/ generate a warning with a lint-like program. Why? Because
x is not a `boolean' in lint's view of the world, even though the
relevant standards expressly and specifically allow scalars (such as x)
to function in a boolean context. lint is wrong, the standards are right
(axiomatically), and lint hasn't been fixed.

Also, remember that lint cannot be trusted to `schedule' or `prioritize'
warnings: Using gets() is seen as just as bad as using an int in a
boolean context. (I hope you know how bad gets() is. I hope it's not
polluted C++ as well.)

All that said, splint is good for C but it won't work for C++: splint
allows you to pass in arguments on the command line that will make it
not generate certain classes of warnings. It's the only lint-a-like I
will use, but I don't develop C++.

So, in short, know the limits of your tools.
 
D

David Rasmussen

Greg said:
We have a large code base, mainly C but with some C++ which we wish to check
for
existing issues in an effort to be proactive.

I have downloaded the open source GLINT program but am having big problems
trying to get it to run.

I will be looking at PC-Lint at http://www.gimpel.com/

As far as I know, no good free C++ lint program exists. I have been
thinking seriously about make one for the GNU project, but haven't had
the time yet. My basic idea is that it should basically be a parser with
easily extendable rules and actions that can be defined by a simple
language in a configuration file. All sorts of things should of course
come predefined.

/David
 
G

Greg Roberts

apologies, yes splint under win32

almost impossible to get all the includes and options correct

Wolfgang Kaufmann said:
* Thus spoke Greg Roberts <[email protected]>:

Hallo,
We have a large code base, mainly C but with some C++ which we wish to
check for existing issues in an effort to be proactive.
I have downloaded the open source GLINT program but am having big problems
trying to get it to run.

glint?

$ man glint

| NAME
| glint - GLINT/Permedia video driver

Do you mean splint? Splint doesn't work with C++ code, see
I will be looking at PC-Lint at http://www.gimpel.com/

Afaik its the best lint (for C and C++ code) out there.


[f'up2 -> poster]

Wolfgang.
 
G

Greg Roberts

I incorrectly said lint where i meant splint, and our env. was MS Visual
C/C++ 6.0 .

Yes you all have mentioned what i found, really hard work to get these to
work
on an existing code base (as i don't really want to have to play with
headers & system headers adnusium) .

Even one expensive tool like C++ Test (U$3500) doesn't look at the MS DSP
files to determine headers to search.

I suspect just adding some basic rules into some Perl scripts will probably
offer the most payback.

Regards
 
A

Alan Balmer

int x = 1;

/* code */

if (x) return y;

will /always/ generate a warning with a lint-like program. Why? Because
x is not a `boolean' in lint's view of the world, even though the
relevant standards expressly and specifically allow scalars (such as x)
to function in a boolean context. lint is wrong, the standards are right
(axiomatically), and lint hasn't been fixed.

Lint doesn't need fixing in this case - it's doing exactly what it's
supposed to do. If I were reviewing someone's code which used this
statement, I would suggest that they change it to

if (x != 0) return y;
 
B

Bob Hairgrove

Lint doesn't need fixing in this case - it's doing exactly what it's
supposed to do. If I were reviewing someone's code which used this
statement, I would suggest that they change it to

if (x != 0) return y;

But why? The C++ standard is quite clear on how this is supposed to
behave. Lint, and MSVC++.NET, BTW, are both wrong.

Of course, if x is not a scalar type, then an error (not a warning)
should be generated.
 
D

David Rasmussen

Bob said:
But why? The C++ standard is quite clear on how this is supposed to
behave. Lint, and MSVC++.NET, BTW, are both wrong.

Wrong? None of them say that it's an error. They say that it is bad
style. Which it is.
Of course, if x is not a scalar type, then an error (not a warning)
should be generated.

They are _not_ generating error messages. You don't understand what lint
is about.

/David
 
A

Attila Feher

Alan said:
Lint doesn't need fixing in this case - it's doing exactly what it's
supposed to do. If I were reviewing someone's code which used this
statement, I would suggest that they change it to

if (x != 0) return y;

And I would change it to

if (0 != x) return y;

At least that was taught to me in programming paranoia school.

BTW the above (if (X) bla) is not bad style (I do nor recall any technical
reason for it) but I think it is rather idiomatic code, and there is nothing
wrong with it.
 
C

Christian Bau

Attila Feher said:
And I would change it to

if (0 != x) return y;

At least that was taught to me in programming paranoia school.

Please don't do this.

First, it is pointless. There are people who write "0 == x" instead of
"x == 0" to get an error message if they write "=" instead of "==", but
for "!=" this makes no sense. Second, it makes your code less readable
which in itself will increase the number of undetected errors. Third, I
sincerely hope that you use a debugger to step through your code at
least once, so an error like that would be detected immediately. Fourth,
"if (0 == x)" wouldn't pass any decent code review for the reasons
above, but neither would "if (x = 0)".
 
R

Richard Heathfield

Christian Bau wrote:

There are people who write "0 == x" instead of
"x == 0" to get an error message if they write "=" instead of "==", but
for "!=" this makes no sense.

Er, 0 != x makes exactly as much sense as x != 0
Second, it makes your code less readable
which in itself will increase the number of undetected errors.

Whether it's less readable is arguable; if it helps people to get used to
the idea of placing constants on the left of comparisons, then - on
platforms with lousy compilers - it could *reduce* the number of undetected
errors.
Third, I
sincerely hope that you use a debugger to step through your code at
least once, so an error like that would be detected immediately.

And yet they so often aren't.
Fourth,
"if (0 == x)" wouldn't pass any decent code review for the reasons
above, but neither would "if (x = 0)".

I wouldn't raise any objections to if(0 == x) at a code review.
 
M

Mark McIntyre

Lint doesn't need fixing in this case - it's doing exactly what it's
supposed to do. If I were reviewing someone's code which used this
statement, I would suggest that they change it to

if (x != 0) return y;

Thats merely obfuscating a perfectly clear expression.

And I agree with August that lint is incorrect - lint should not be
complaining about legal constructs.
 
P

Peter Pichler

Richard Heathfield said:
Er, 0 != x makes exactly as much sense as x != 0

To a compiler, yes. If you have learned to think like one, congratulations.
I wouldn't raise any objections to if(0 == x) at a code review.

But neither would you to if (!x), I hope.

Peter
 
R

Richard Heathfield

Peter said:
To a compiler, yes. If you have learned to think like one,
congratulations.

Um... um... thank you! (?!?!?)
But neither would you to if (!x), I hope.

Depends on the house style, of course (as does the 0 == x one, actually!).
But my own preference is to reserve (x) and (!x) for where x clearly has
Boolean intent, e.g. if(PrinterReady), while(!finished), and so on.
 
L

lilburne

Attila said:
And I would change it to

if (0 != x) return y;

At least that was taught to me in programming paranoia school.

BTW the above (if (X) bla) is not bad style (I do nor recall any technical
reason for it) but I think it is rather idiomatic code, and there is nothing
wrong with it.

The idiom 'if (x) bla;' had certain advantages over the
construct 'if (0 != x) bla;' before compilers grew up. A
number of compilers I used circa K&R used to compile a
compare rather than a test. Nowadays there is no advantage
and the second version is more readable. The one line
statement has a problem though should you ever want to place
a breakpoint on the 'return';
 
L

lilburne

Mark said:
And I agree with August that lint is incorrect - lint should not be
complaining about legal constructs.

Why should that be? Isn't it the compilers responsibility to
complain about none legal constructs?
 
M

Mark McIntyre

Christian Bau wrote:



Er, 0 != x makes exactly as much sense as x != 0

indeed.
but you're less likely to miss out the ! in != than the = in ==, which
was CB's point, I suspect.
 
C

CBFalconer

Richard said:
Christian Bau wrote:


.... snip ...


I wouldn't raise any objections to if(0 == x) at a code review.

Nor would I, nor to "if (0 != x)". In fact I would be more likely
to complain about use of "if (x == 0)".

Just stirring the pot with a vote - minor troll.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top