Hi, I'd like to propose adding .clang-format file for mingw-w64.
Currently, the code style is mixed, and sometimes uneasy to read.

As a startup, I tried to draft an example .clang-format for 
mingw-w64-headers/crt.
The reason for choosing it is that these headers are most frequently accessed 
by users,
so readablity and unified code style would be more important.

I tried to keep the most common used original code style, except for the 
following 2:

1. PointerAlignment: Left. Right alignment is used more common, but IMHO it 
splits qualifier grouping.
For example, with left alignment:
char* __cdecl strcpy(char* __restrict__ _Dest, const char* __restrict__ 
_Source);
With right alignment:
char *__cdecl strcpy(char *__restrict__ _Dest, const char *__restrict__ 
_Source);
Left alignment will group 'char*' as a type, while right alignment '*__cdecl' 
and '*__restrict__',
which I think is less proper in semantics.

2. IndentPPDirectives: AfterHash. Never indent is used more common, except in 
several _mingw* files
where macros are extensively used. Indent preprocessore directives can 
extremely increase readability
for nested #ifdef, which is common in CRT headers. Note that header guard is 
recognized by clang-format,
and will always be NOT indented.

The following .clang-format is just a draft, and any changes are welcome. I'm 
not sending the whole
changeset as a patch, as it is very huge, unreadable, and can be easily 
generated with:
`clang-format -i mingw-w64-headers/crt/{*,**/*}.{h,inl,in}`. Note that it'd be 
better to add the SHA
of the future commit that actually did the format to `.git-blame-ignore-revs`, 
to make it ignored when
using git blame.

---

>From 8de12216691fe3a5922e959a79a0f2912ba21013 Mon Sep 17 00:00:00 2001
From: Zhongteng Gui <[email protected]>
Date: Wed, 2 Sep 2026 00:13:54 +0800
Subject: [PATCH] headers: crt: Add .clang-format

Signed-off-by: Zhongteng Gui <[email protected]>
---
 .gitignore                          |  1 +
 mingw-w64-headers/crt/.clang-format | 31 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 mingw-w64-headers/crt/.clang-format

diff --git a/.gitignore b/.gitignore
index 3d1022348..2a20003c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 # Temporary files
 *~
 .*
+!.clang-format
 
 # Compiled files
 *.o
diff --git a/mingw-w64-headers/crt/.clang-format 
b/mingw-w64-headers/crt/.clang-format
new file mode 100644
index 000000000..784e1947e
--- /dev/null
+++ b/mingw-w64-headers/crt/.clang-format
@@ -0,0 +1,31 @@
+BasedOnStyle: LLVM
+Language: Cpp
+
+ColumnLimit: 0
+
+PointerAlignment: Left
+
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterFunction: true
+  SplitEmptyFunction: false
+  SplitEmptyRecord: false
+  SplitEmptyNamespace: false
+
+AllowShortBlocksOnASingleLine: Empty
+AllowShortEnumsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+
+IndentPPDirectives: AfterHash
+AlignEscapedNewlines: DontAlign
+SkipMacroDefinitionBody: true
+
+AlignTrailingComments:
+  Kind: Leave
+BreakAdjacentStringLiterals: false
+FixNamespaceComments: false
+ReflowComments: Never
+SortIncludes: Never
+SortUsingDeclarations: Never
+
+InsertNewlineAtEOF: true
-- 
2.55.0.windows.5



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to