Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
1 answer
53 views

clang-format option to set penalty for breaking preprocessor directives

Is there an option to set the penalty for breaking preprocessor directives into multiple lines? For example, if I have the following snippet: #define my_constant 1 // Lorem ipsum dolor sit amet, ...
skillz21's user avatar
  • 176
0 votes
0 answers
154 views

How can I make VS Code format C/C++ function return types on their own line?

I'm on macOS. GNU C++ in Visual Studio Code automatically format like int main () { ... } Instead I want to do : int main() { ... } Follows my current settings: "[cpp]": { "...
Juan J's user avatar
  • 37
0 votes
1 answer
221 views

How to add custom separator between functions using clang format?

I have a C and C++ code base which I format using clang format. I'd like to make my code easy to read by placing separators between functions in the following way: //-----------------------------------...
locke14's user avatar
  • 1,365
1 vote
1 answer
561 views

clang-format always indent struct initiallizers

i have a very strange behavior with my current .clang-format file. here is the file: --- BasedOnStyle: LLVM ColumnLimit: 200 IndentWidth: 4 UseTab: Always TabWidth: 4 BreakBeforeBraces: Linux ...
eddy's user avatar
  • 518
1 vote
0 answers
44 views

clang format space before parens in function call except for short names like gettext helpers?

An example of a common style pattern is: return g_strdup (_("24-hour")); label = g_strdup_printf (C_("timezone desc", "%s (%s)"), ... I.e. space between function name ...
Oskar Berggren's user avatar
3 votes
1 answer
293 views

clang-format adds newline before typedef name when struct defined with macro __PACKED_STRUCT

I am running clang-format on my C code which includes a large number of packed structs like this. It keeps moving the typedef name onto a new line following the closing brace. Is there a way I can ...
Zerovoid's user avatar
0 votes
1 answer
1k views

VScode C/C++ formatting failed

I'm on windows 10, It used to work before i don't know why it stopped working, it gives the error message "Formatting failed. See the output window for details." refer to I've looked for a ...
borygamer's user avatar
0 votes
1 answer
896 views

C/C++ How to format if conditions' single statement on the same line in VScode

If you don't use curly braces in C/C++ after declaring a condition, the body of the function becomes the next statement directly after; same thing for loops (while, for etc....). I want the formatter ...
borygamer's user avatar
0 votes
0 answers
499 views

How to properly align types, variables, storage specifiers and values with clang-format?

I am compelled to investigate using clang-format to modify my code, and I am looking for some help with certain things. Here is an example of our style, which I need to replicate: /********************...
Walkingbeard's user avatar
1 vote
2 answers
2k views

VSCode removing spaces with auto format (C/C++)

I recently migrated to VSCode and I really like the auto formatting, but how do I configure it not to remove spaces? I have a sort of matrix I use to configure GPIO pins and I use spaces to make it ...
Matt's user avatar
  • 2,650
1 vote
0 answers
562 views

How to force clang-format break after variable type?

I couldn't make clang-format make code like this static inline return_type_t foo( long_name_arg1_t **a, arg2_t b, arg3_t *c ) { var_type_t var1, var2, ...
Pavel.Zh's user avatar
  • 467
-1 votes
3 answers
73 views

function generalization in C

im fairly new to C. i've written the following code. and all the following functions are nearly identical. i just want to know is there is a way to reduce the following functions into a generic one ...
hammi's user avatar
  • 878
0 votes
2 answers
2k views

VSCode - disable comments auto-formatting for C code

I just installed an extension prettier in vscode to autoformat my code. However all the comments in my code are being moved towards the left. Which I don't want. Before formatting: enter image ...
Samuel Hetteš's user avatar
3 votes
1 answer
2k views

clang-format makes changes to an already formatted file

When formatting the same file with the clang-format command line tool twice, changes are made both times. My understanding is that once formatted, attempting to re-format the same file should not ...
Nikola Špirić's user avatar

15 30 50 per page