Reputation: 2617
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;
Upvotes: 2
Views: 512
Reputation: 43206
Use -pal
From the GNU indent manual:
-pal
--pointer-align-left
Put asterisks in pointer declarations on the left of spaces, next to types:
“char* p”
.
Upvotes: 1
Reputation: 70353
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;
Upvotes: 3
Reputation: 62603
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
Upvotes: 2
Reputation: 181104
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.
Upvotes: 1