Line break means something in C / C ++?

I merged the two branches of software and in the process of merging, I remained as follows:

if (b_flag)
 DoSomething();
 //MERGE
else
 //ENDMERGE
  DoOtherThing();

See disabling the if / else block? Does it work as supposted? Do compilers account for line breaks?

+3
source share
4 answers

Yes, it will work as intended. If you have ifor elsewithout curly braces ( {}), the following statement is treated as an if body. Inserting line breaks or comments does not alter the fact that DoSomething (); or DoOtherThing (); these statements.

+7
source

, , , " ". , , , - .

, , else, , , "if block", else else if .

, .

+6

. , , - .

Edit: the only time a newline matters is in the C preprocessor directive, for example #define.

+2
source

This works exactly as if braces were used.

+1
source

Source: https://habr.com/ru/post/1790494/


All Articles