Search code examples
c++vimindentation

GNU indent: does it support C++


I used indent to format my C code and it works very well.

Now I'm working with C++ and I still want to use indent. However, I find that it does not support the class declaration very well. Here is an example:

class Test
{
public:
    Test ();
    void ttt ();
protected:
    virtual void func ();
};

This is a header file named test.h and after using indent like this: export VERSION_CONTROL=never; indent -bli0 -blf -bls -nbfda -npsl -i4 -ts4 test.h, it becomes as below:

class Test
{
  public:
        Test ();
        void ttt ();
  protected:
          virtual void func ();
};

As you see, before public and protected, two spaces are added and virtual vodi func(); isn't aligned at all.

So indent doesn't support C++?


Solution

  • No, GNU indent does not support C++.

    Quoting section 1.12 of the GNU indent manual:

    While an attempt was made to get indent working for C++, it will not do a good job on any C++ source except the very simplest.