with gnu indent how to make int * to int*

code for indentation in c
gnu indent examples
how to indent a paragraph in c++
linux indent
c beautifier linux
indentation error in c
indentation in programming
indent format in excel

I want to change

int *i;

to

int* i;

using gnu indent. How can I go about doing that?

If not possible how to at least make kernighan&ritchie style

int * i;

to

int *i;

I believe, gnu ident doesn't have this option. CLang format, on the other hand, seems to have it as PointerAlignment option, which can take following options:

Possible values: PAS_Left (in configuration: Left) Align pointer to the left.

int* a;

PAS_Right (in configuration: Right) Align pointer to the right.

int *a;

PAS_Middle (in configuration: Middle) Align pointer in the middle.

int * a;

More details can be found here: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Newest 'gnu-indent' Questions, 3. with gnu indent how to make int * to int* · c++ c gnu-indent · Dec 6 '18 at 6:58 DevSolar. 0. 2. how do I set space between function name and parenthesis with  1. The indent Program . The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax. In version 1.2 and more recent versions, the GNU style of indenting is the default.

I did not find any corresponding option in the GNU indent manual. An alternative would be to use AStyle, which offers the --align-pointer option:

With --align-pointer=type / -k1:

int* a;

With --align-pointer=middle / -k2:

int * a;

With --align-pointer=name / -k3:

int *a;

with gnu indent how to make int * to int*, with gnu indent how to make int * to int*. code for indentation in c gnu indent examples how to indent a paragraph in c++ linux indent c beautifier linux indentation  1. The indent Program . The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax.

How can I go about doing that?

If not possible how to at least make kernighan&ritchie style

The documentation for GNU indent does not clearly describe any option specifically affecting the whitespace around the asterisk in a pointer declaration, but it does have an umbrella option -kr for requesting K&R style, and I find that that does cause indent to perform the formatting you request, snuggling up the asterisk next to the identifier. Of course it has many other effects, as well, though these can be overridden by additional explicit options.

The -gnu general style option, which is the default, also has this effect. That makes it tricky to sort out which detail option controls this specific behavior, but certainly one answer to your question is that indent will convert your pointer declarations to the K&R style you describe with no options at all.

In fact, as far as I can tell, indent will perform that particular formatting regardless of what options you provide. There does not seem to be any option to modulate that behavior.

indent: Indent and Format C Program Source, The indent program can be used to make code easier to read. It can also int foo () { puts("Hi"); } /* The procedure bar is even less interesting. The GNU C compiler extends the language to contain long long integers as well. The C integer types were intended to allow code to be portable among machines with different inherent data sizes (word sizes), so each type may have different ranges on different machines.

Indent - The @code{indent} Program, It can also convert from one style of writing C to another. indent understands a In version 1.2 and more recent versions, the GNU style of indenting is the default. int foo () { puts("Hi"); } /* The procedure bar is even less interesting. In computer programming, an indentation style is a convention governing the indentation of blocks of code to convey program structure. This article largely addresses the free-form languages, such as C and its descendants, but can be (and often is) applied to most other programming languages (especially those in the curly bracket family), where whitespace is otherwise insignificant.

indent, The indent program can be used to make code easier to read. In version 1.2 and more recent versions, the GNU style of indenting is the default. int baz; indent -bad produces char *foo; char *bar; /* This separates blocks of declarations. Indent statement (if, while, for, etc) parentheses Property names: [resharper_]cpp_indent_statement_pars, [resharper_]indent_statement_pars. Possible values: inside: Inside parenthesis (BSD/K&R style) outside: Parenthesis and inside equally (Whitesmiths style) outside_and_inside: Parenthesis 1x, inside 2x (GNU style) none: No indent. Examples:

man indent, In version 1.2 and more recent versions, the GNU style of indenting is the default. `indent' has a number of options to insert or delete blank lines in specific places. int baz; The `-bap' option forces a blank line after every procedure body​. Introduction to Indent. The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax.

Comments
  • In int* a, b; What type does the variable b has in your opinion?
  • "*i is of type int" is correct. Also int *i, j; clearly shows that j is not a pointer whereas int* i, j; makes j look like a pointer. Anyways, consider using clang-format.
  • Is the question here "How do I use gnu indent?" or "Which style is better?"
  • This question is about getting the result desired by the OP from GNU indent. Please do not discuss whether that result is good or bad in your opinion.
  • @AlgirdasPreidžius How often do you write code like that? Still don't understand why people keep anchoring themselves to one edge case in this debate.
  • Should be a comment really, as it does not exactly answer the question...
  • But this option is horrible clang-format does not make the difference between the * inside a ptr-declarator and the * of the indirection expression. I don't use clang format just for that!
  • @DevSolar well, I think it does, as OP has somewhat like an XY problem. The tool chosen by OP doesn't have this functionality, but there is a replacement tool. I believe, it is a valid answer, which doesn't really fit into comment.,
  • Valid answers to the question "how do I,,,?" include "you cannot" —unless incorrect.
  • @DevSolar and I believe, this is a valid answer to, which I upvoted :)