Thread: Code formatter for indentation, style...

  1. #1
    Registered User
    Join Date
    Dec 2009

    Code formatter for indentation, style...


    I am trying to format a C++ code base to conform to a propitiatory coding style, such as how braces are placed, indentations, white spaces, etc. I tried Eclipse CDT formatter, but it would put some brace at the wrong places (about 20%).

    Could anyone provide suggestions that what may be good tools to use for this kind of task for C++ project?


  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    I really hope that the environment you plan to maintain/edit/create code in can be customized to match this new coding style (otherwise that's step one). Once you have that set, most editors/IDEs have a command to reformat code based on the defined style.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Start with if the options it offers are enough. It's online and thus a nice option for that one instance when you really need something like that.

    If that isn't enough, move to an editor with code formatting options. I know nothing about eclipse, but depending on the operating system you have plenty of options. Just load up the code into the IDE, configure its settings and run the command that allows you to format the code.

    If you have complex requirements, and if you need to do this often, you will want to buy Polystyle.

    EDIT: tabstop makes a good point too. It's no use to you any editor that cannot be configured for your style, so that's your priority. And since editors usually have an option to reformat code, this should also be your only priority.
    Last edited by Mario F.; 01-12-2011 at 09:41 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Astyle is my choice - it's incredibly powerful, and it's free. A lot of IDEs have plugins for Astyle but the Eclipse one leaves much to be desired and I wouldn't recommend it. If IDE integration is a must the Code::Blocks plugin is very nice.

    Since it's a command-line tool, however, it may be just as effective to add an 'Astyle' command with parameters as you see fit, as a macro in Eclipse (Actually IIRC Eclipse calls them 'tools').
    Consider this post signed

  5. #5
    Registered User
    Join Date
    Dec 2009


    Thank you so much for providing the information!
    I will try and find out which may match the style.

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    In eclipse you can change the formatting options in the preferences to be whatever you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Humorous Code
    By DavidP in forum General Discussions
    Replies: 16
    Last Post: 08-28-2010, 10:40 AM
  2. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  4. C++ Code Formatter
    By Visual Develope in forum C++ Programming
    Replies: 4
    Last Post: 05-28-2002, 04:18 PM