Hi guys,
I was wondering if there is a function or tool in an editor.. or program that can add const modifiers to parameters that aren't changed withing a function.. etc..
Thanks,
Ed.
Hi guys,
I was wondering if there is a function or tool in an editor.. or program that can add const modifiers to parameters that aren't changed withing a function.. etc..
Thanks,
Ed.
I think the question was more about whether there is a tool that can automatically analyze the code and determine where "const" can be added.
There are such tools but I don't know of any free ones, and the commercial ones do not come cheap. Coverity is one popular tool for static source analysis. It starts at $30,000.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
That was my intended point, though. Kind of. Yes.
A simple tool might detect variables that aren't modified and change them to const.
But are there tools that can detect which variables really should be const? That's the question, and probably is more of a design issue rather than a tool issue.
hmm very interesting, I didn't know it would be so expensive :\.There are such tools but I don't know of any free ones, and the commercial ones do not come cheap. Coverity is one popular tool for static source analysis. It starts at $30,000.
Yesterday
What about stuff for:
-Detecting unnecessary includes
-Detecting functions that are not implemented. Since when modyfing others code I end up moving only class method implementations I need, and I have a bunch declared that are not implemented.
-Detecting unused variables?
I work develop right now mostly in linux, so a linux tool would be preferable.
Ed.
The linker will do that. Only when they're used, of course.Detecting functions that are not implemented.
Try enabling all warnings (-Wall -Wextra) and optimization (-O1 or higher) in GCC.Detecting unused variables?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Detecting unused includes is pretty easy, unless the project is enormous, by experimenting - just remove the include and compile - if compiles without warnings & errors, then it's not needed. It gets a bit harder if you have many different configuration options, but it's usually doable. Start with files that have a large proportion of include vs. actual code (where you have the biggest gain!).
I don't know of any tool that actually does this for you, however.
A cross-referencing tool can also help you with all manner of things - however, classes and pointers to classes can lead to interesting effects, e.g.
The linker will probably complain if you don't implement B::foo(), but if you never actually call func() with a pointer to B - because of the way that func is being used - then it's very difficult to discover - I don't think coverity can do that either (I have used coverity a little bit - but not a whole lot).Code:class A { public virtual void foo(); }; cass B: public A { public: virtual void foo(); }; void func(A *ptr) { ptr->foo(); }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
That's what I meant by "but it gets harder if you have many configurations" (as the different configurations will mean many compiles with either different compilers or different settings).
Beware of differences between debug and release builds too - release builds may not use the logging code, which is produced in a debug build. So when you remove say, stdio.h, then the code will build in release form, but not in debug form.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
By cross-referencing tool, do you mean something like eclipse's indexing.. though its indexing isn't very good, sometimes I'm frustrated on how it is so INCONSISTENT.A cross-referencing tool can also help you with all manner of things - however, classes and pointers to classes can lead to interesting effects, e.g.
What cross-referencing tool would you recommend me, matsp?
We use a version of "linux cross reference", which is used on this site:
http://lxr.linux.no/
It's not perfect, but it's pretty good. Source code for that site is available via link on the above page.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
> or program that can add const modifiers to parameters that aren't changed withing a function..
Lint will do a lot of that, and at around $400 (oh man, it's gone up!) for a single-user licence, it pays for itself with the first bug it finds that you no longer have to spend a day looking for the old fashioned way.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
They're the same product (with different names) for different markets.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
There are open lint implementations. For example FreeBSD includes one and I'm sure it isn't any closed source implementation.