IDE 1.8.5 autoformat with const and curly braces

const float fred{20.0};
const float george{10.0};

is autoformatted as:

const float fred {
const float george{10.0};

Only for const, and only in the first code line. Happens for all types I tried. Does not happen if you initialise using () or =. Code valid of course, just a little odd. Inserting nl, spaces or comments doesn't work around it.

I believe autoformat comes from, and I had an old version to try, and the format expands like the first line, and does it for all, consistently. So perhaps, if this is a bug, it appeared in the port? Just a guess.

What am I doing wrong?

thanks royd.

I’m not familiar with that syntax. What does it do?

Auto format is done by Astyle:
so the different behavior you’re seeing could be caused by different versions of Astyle.

That's a list initialization. An advantage is that it doesn't allow narrowing. However, the AVR compiler doesn't seem to care ...

You can use:

const float fred = {20.0};

(I don't really see why you would use a float to store 20 though.)


Thanks guys. There are more important things in the world of course! I was just a little surprised at the inconsistency. I'm certainly no expert on C++ syntax, but apparently the C++11 standard includes something called "uniform initialisation", which is equivalent to the other () and = formats. It looks like a list, but without the comma, a single item, arguably a single item list. In any case, the compiler is happy, but the formatter behaves inconsistently. I'll have a look at Astyle and see what it does. Thanks for the moment.

oh, ps, of course the code is silly :) the same problem occurs with ints, chars, bytes, you name it.


Astyle has lots of options for setting formatting preferences. The Arduino IDE’s settings are here:
or in the lib subfolder of your Arduino IDE installation folder. You could compare the settings between the working and nonworking programs to see if that’s the cause.

I believe autoformat comes from, and I had an old version to try,

Old version of Processing or the Arduino IDE?

the format expands like the first line, and does it for all, consistently.

Wouldn’t the desired behavior be to not expand? Of course consistently formatting in a less preferable way is better than inconsistently formatting as desired.

I never understand the use of curlies in this scenario.

const float fred = 20.0;
const float george = 10.0;

Or with curlies

const float fred = {20.0};
const float george = {10.0};

In both cases the auto-format problem is gone; not the use of the equal sign.

agreed. formatting using {} without the = appears odd to me too, as originally a C programmer. But its the inconsistency that irks, and happening on the first line only suggests a defect somewhere. I’ve downloaded the windows exe for astyle, and it seems to work consistently. I’ll do the same with the Linux version and do a better test with the same Arduino config file. Thanks for the link to that.


Just spent 30 minutes reading the astyle documentation and looking for something that might cause const and "braces" (as they call "{}") to be handled differently on the first line. Tried various things using the windows version. Also used the format.conf as shared above, and a few other styles (there are many, e.g. allman, google, java etc). Cant yet make it behave the same way, but more odd, I can see no option that would even do this peculiar behaviour, even if you wanted it. I'll need to take a look at the IDE code next, to see how it hands off the sketch to the formatter. Thanks r.

quick update… the controls for the formatting in the IDE is held at \lib\formatter (for me its C:\Program Files (x86)\Arduino\lib\formatter. Astyle options are held here. Change it, and restart the IDE to take effect. I added


and the braces are not split. These options control how code blocks held within braces are handled, not apparently differentiating between a code block’s use of braces, and the C++11 use in uniform declaration. If, as it appears, the latest Astyle leaves declarations alone, then this could be a feature of the version of astyle used in the IDE (predates C++11??), and perhaps fixed in the latest version. More experimenting with Astyle, and check which version is used etc. to come.


1 Like

Got to the answer here. In IDE v1.6 the astyle formatter was updated to 2.05 (

I tested windows version 2.05 and sure enough it mangles first line "const int fred{20};"

I did the same test with the latest astyle, v3.1, and the formatting is correct. Appears to be a version issue with the current IDE. When it gets updated to the latest astyle, then this will be fixed. Of course, this is a small bug, and I'm happy to wait.

Thanks all R

Good work tracking it down!

If you want to push this forward, I recommend you open an issue report requesting that astyle be updated here:

Clearly the Arduino developers take an "if it ain't broke don't fix it" attitude with astyle so without prompting it could be a very long time before they decide to update to the new version. As you said, this is pretty minor, so it still might not be a high priority but it's worth a try.

Thanks pert.

I take your point, and at least the request will be on the list for the next time the bonnet is up. There is one other potential bug on the list already, so I will add this. Looking at the previous issue, it would demand updating to the latest version first anyway IMO.

Thanks for your guidance, I wasn’t sure of current practice and custom wrt raising issues.