c++warnings

Warning message purpose?


While compiling a while loop without a body, I saw this message:

warning: suggest a space before ';' or explicit braces around empty body in
'while' statement

Why should I put a space? Is it to make it clearer that my loop isn't really doing anything?


Solution

  • Yes -- the usual convention is to put it on a line by itself, something like this:

    while (*d++ = *s++)
        ;
    

    A few people prefer to use things like:

    while (*d++ = *s++)
    {
        /* intentionally empty */
    }