Eclipse, how can I defer C ++ preprocessor macros

I cannot find the parameter in eclipse, so that I can automatically cancel it my preprocessor macros in the same way as the indentation code. For example, eclipse is trying to format such code.

int main() { #ifdef SOMETHING cout << "Something Defined" << endl; #endif return 0; } 

While I want it to look like ...

 int main() { #ifdef SOMETHING cout << "Something Defined" << endl; #endif return 0; } 

Any ideas to do an eclipse to do it the way I want?

+8
c ++ eclipse
source share
5 answers

The pre-ANSI C preprocessor did not allow a space between the beginning of the line and the "#" character; the leading "#" should always be placed in the first column.

There are no Pre-ANSI C compilers these days. Use any style (space before "#" or space between "#" and identifier).

But I suggest you do this: enter image description here

Just use the Find / Replace dialog and click Replace All.

+2
source share

The Eclipse indent is correct. Preprocessor directives should be in the leftmost column, regardless of the indentation of the surrounding code.

+1
source share

I think there is no macro for indentation. But I see that clangformat seems to have a parameter for indenting the macro, so you can configure your own clang format ( http://clang.llvm.org/docs/ClangFormatStyleOptions.html ) and configure eclipse to use clangformat instead of the default.

+1
source share

To backtrack from the preprocessor, you may need to use Neatbens instead. This formatter ignores preANSIc.

+1
source share

Like the others, the already-specified compiler directives # must begin in the first column to comply with the standard. However, they are allowed to leave spaces. So my preferred solution is as follows, and then it should no longer be an eclipse problem.

 int main() { # ifdef SOMETHING cout << "Something Defined" << endl; # endif } 
0
source share

All Articles