Peter
Peter

Reputation: 11920

Is there a way to modify Google C/C++ formatter in Visual Studio Code?

I like Google formatting option for C/C++ extension in VCS. However, there is one aspect I would like to change.

I prefer associating a pointer or a reference to the type declaration:

int& a = b;
int* c = d;

However, Google formatter changes it to:

int &a = b;
int *c = d;

I am wondering if there is a way to override just this formatting aspect. Regards.

Upvotes: 2

Views: 1332

Answers (1)

Rohan Bari
Rohan Bari

Reputation: 7726

From the clang-format-reference:

DerivePointerAlignment (bool)

If true, analyze the formatted file for the most common alignment of & and *. Pointer and reference alignment styles are going to be updated according to the preferences found in the file. PointerAlignment is then used only as fallback.

Consider an example code:

int b = 10;
int *d = &b;
int & a = b;
int *c = d;

If you try to format this code in VS Code, you will find that the 3rd line has automatically formatted as int &a = b. Again, consider the same version of code in different style:

int b = 10;
int* d = &b;
int & a = b;
int* c = d;

Now, you will see the 3rd line as: int& a = b.

Upvotes: 1

Related Questions