6

I was wondering if there is any way to add braces in nested If-else using Uncrustify. For example:

if( stat_error == -1 ){
   if ( debug > 0 )
      printf( "...ERROR ); //I would like to add braces around here.
   exit( -1 );
} else {

I have seen this:

# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
mod_full_brace_if                        = add   # ignore/add/remove/force

But it doesn't seem to work for nested conditionals.

Is there any way to do it?

durron597
  • 31,968
  • 17
  • 99
  • 158
Cod1ngFree
  • 1,873
  • 6
  • 21
  • 33

2 Answers2

4

My experience with Uncrustify in your example :

Add or remove braces on single - line if statement. Will not remove the braces if they contain an else.

mod_full_brace_if = add

Make all if / elseif / else statements in a chain be braced or not. Overrides mod_full_brace_if.

If any must be braced, they are all braced. If all can be unbraced, then the braces are removed.

mod_full_brace_if_chain = false

And it worked for me.

Community
  • 1
  • 1
mtb
  • 1,350
  • 16
  • 32
-4

you need to add a return statement should look like this

    if( stat_error == -1 ){
   if ( debug > 0 )
      printf( "...ERROR ); //I would like to add braces around here.
   exit( -1 );
} else{

Insert else statement
}
return statement here
}
macguy3
  • 15
  • 8