Arduino Forum

Development => Suggestions for the Arduino Project => Topic started by: adlmail on Jan 23, 2018, 01:48 am

Title: make the compiler friendlier by matching brackets
Post by: adlmail on Jan 23, 2018, 01:48 am
The error messages that result from inadvertantly erasing a } bracket are so obscure they often do not lead to the problem.

How about adding a simple bracket counter so if there are a different number of left brackets than right brackets it tells you to look for that.  This would sure help us beginners.
Title: Re: make the compiler friendlier by matching brackets
Post by: groundFungus on Jan 23, 2018, 02:05 am
Or adjust your writing style so that mis-matched brackets are easier to see.  Put every { and every } on its own line.
Code: [Select]
if(a ==1)
{
   If(b==1)
   {
      doThis;
   }
}


Couple that with auto format and misplaced brackets usually stand right out.
Title: Re: make the compiler friendlier by matching brackets
Post by: aarg on Jan 23, 2018, 02:20 am
What version of the IDE do you have? The latest ones highlight bracket pairs and even display function names if they end one.
Title: Re: make the compiler friendlier by matching brackets
Post by: terryking228 on Jan 23, 2018, 02:39 am
Quote
The latest ones highlight bracket pairs
You need to click next to a bracket and then the matching one of the pair is highlighted.

Another help for bigger sketches is to use the free editor "Notepad++"  and set the language to C++. Then it highlights all the bracket pairs including embedded ones. See:

https://notepad-plus-plus.org/ (https://notepad-plus-plus.org/)

That's what I use when I get really screwed up!
Title: Re: make the compiler friendlier by matching brackets
Post by: TKall on Jan 23, 2018, 02:48 am
In Visual Studio you can highlight one brace, click ctrl+] and the cursor will jump to the matching brace.
Title: Re: make the compiler friendlier by matching brackets
Post by: aarg on Jan 23, 2018, 02:53 am
reply #1 is the solution
Title: Re: make the compiler friendlier by matching brackets
Post by: PaulS on Jan 23, 2018, 01:21 pm
Tools + Auto Format WILL tell you that you have the wrong number of right or left braces, or will line things up neatly, though not necessarily correctly, if you have the same number of each.