<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56245>56245</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format --length behavior
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shymanelaw
</td>
</tr>
</table>
<pre>
From the documentation:
`--length=<uint> - Format a range of this length (in bytes).`
The way I read this is that a piece of text that is equal to the number of bytes will be formatted.
I've counted the number of bytes for the first 2 lines (I know there is a `--lines` option, it's just an example):
- with `microsoft` style, only those 2 lines are formatted;
- with `gnu` and `mozilla` styles the whole function is formatted.
I can't figure it out. Styles have the same options, but use different values.
Is this specific to the formatting options, or a `--length` behavior I don't fully understand?
```c
int get_number(
int x, int y, int z)
{
if (x > y) { return x + y + z; }
else
{
return x - y - z;
}
}
int main(void){
return 0;
}
```
```bash
clang-format --version
# clang-format version 14.0.0
# Show the number of bytes for the first 2 lines
head -n 2 example.c | wc -c
# 38
# Microsoft style
clang-format --style=microsoft --length=38 example.c
// int get_number(int x, int y, int z)
// {
// if (x > y) { return x + y + z; }
// else
// {
// return x - y - z;
// }
// }
// int main(void){
// return 0;
// }
# GNU style
clang-format --style=gnu --length=38 example.c
// int
// get_number (int x, int y, int z)
// {
// if (x > y)
// {
// return x + y + z;
// }
// else
// {
// return x - y - z;
// }
// }
// int main(void){
// return 0;
// }
# Mozilla style
clang-format --style=mozilla --length=38 example.c
// int
// get_number(int x, int y, int z)
// {
// if (x > y) {
// return x + y + z;
// } else {
// return x - y - z;
// }
// }
// int main(void){
// return 0;
// }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VsGSmzgQ_Rp86YLCYBv7wGFnHKfmkFySPW8JEKCskBwk2eP5-rQQ2JixN97dVCjKRmr16-73WqBMFqd018oGdE2hkLlpqNBEMym8-A8v3Hrh8LsKfZ9TUenai7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