开发者

What does an If statement followed by a semicolon instead of curly brackets mean in C++?

I was recently looking at some vp8 sample decoder code when I came upon this.

开发者_如何学运维
for(y=0; y<img->d_h >> (plane?1:0); y++) {
    int iLength = img->d_w >> (plane?1:0);
    iFrameCursor += iLength;

    if(fwrite(buf, 1, iLength, outfile)); //This semicolon
        buf += img->stride[plane];
}

Any idea what the if statement means?


The semicolon here is the same as if you had said { }. It is just an empty statement.

The following lines of code all do the same thing:

if(fwrite(buf, 1, iLength, outfile));

if(fwrite(buf, 1, iLength, outfile)) { }

fwrite(buf, 1, iLength, outfile);

This is probably an error.


if (<expr>) <statement>

usually the statement is a code block but it can be an empty one statement(;).

the code is equivalent to:

fwrite(buf, 1, iLength, outfile);
buf += img->stride[plane];


If its a colon, it is used instead of brackets. This probably seems like a mistake.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜