4

I was given a big chunk of uncommented code (around 3k lines) that I need to port to another platform. After quite some time going trough this mess I have an idea of what it does.

During this time I was thinking there must be a tool to help on process like this since many things could be automatized.

Do you know any tool that can do some of these things?

  • Open a folder, go trough all the .c and .h files and point out what functions are unused (I found out at least 20% of the functions were never used, perhaps copy paste from other project).
  • Find and make possible to change every function and variable only used on its own .c file as static. Don't know why everything was made public.
  • Clean up the code so all the variables are up in the code, followed by function definitions and make the .h file order be the same as the .c one. This could be useful for any project really.
  • I could think of many more. Something must really exist!
  • The first thing that I on every new contract is to run DoxyGEn over the code base. It generates an incredible amount of useful information, such call trees and more – Mawg Jul 5 at 6:47
2

For the general formatting stuff, I'd suggest looking into clang-format, it's one of the best tools out there right now for this type of thing, and comes with a bunch of predefined formatting styles.

For the general coding stuff, you want to find a good static analyzer. I unfortunately don't have any good one to recommend myself as I don't do much with C, but there are bunches of options out there. This may not be able to automate fixing coding issues, but it will at least automate finding them.

As far as dead code elimination (your first point), you probably can't automate the removal of the functions, but you should be able to find them pretty easily. Most static analyzers provide some way to find such code, and there are some other tools that will generate call graphs from source code which you can inspect to see what is actually being called. Be very careful doing this though, there are a lot of different ways a function can be called, and automated tools generally don't track all of the properly (also be really careful if you're providing API's for plugins or anything like that, code that looks dead may be part of the external API).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.