Why is the following do-while loop valid?

The loop is as follows:

do;
while(1);

Why doesn't the above loop give a syntax error?

I am using mingw gcc compiler

+4
source share
5 answers

This code looks like it was written to obfuscate its meaning, but if we look at the draft C99 draft section, 6.8.5Iteration Operators, Grammar for do while:

do statement while ( expression ) ;

and the statement can be an expression of an expression, which in turn can be a null expression that is ;. So this is the same as:

do
  ;
while(1);

6.8.3 , 3:

null ( ) .

+7
do
    ; //nop
while(1);

:)


, ; Null Statement.

+6

do-while,

do
    no_op(); // do nothing
while (1);

do {
}
while (1);
+2

, .

do continue;
while (1);
+2

;.

do
{
   ;

}while(1);
+1

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


All Articles