I've seen this code referenced in two different places, yet I haven't seen anybody bring this up, but it seems that on line 00339 there is an empty if block and I just copied the code to compile try it out but it won't even compile cause of that.

if (frame_count >= STREAM_NB_FRAMES) {
 /* no more frame to compress. The codec has a latency of a few
    frames if using B frames, so we get the last frames by
    passing the same picture again */
} else {

Any idea or explanation why it is like that. Is it a mistake on the author's part when copying it? What is supposed to be going on in that if block anyways?


There is no mistake. The if part of that block is indeed empty.

It is often easier to express the logic by making the if part empty and doing the work in the else part. In, this case, the if part has a comment specifically explaining why it is empty and why there is nothing to do.

The code is legal C and will compile fine.

  • Ah, there is my problem them. I'm trying to use it in C++... Any easy hacks that can be done to make it c++ compatible?
    – bitterman
    Feb 9 '12 at 14:26
  • The code is perfectly legal C++. No hacks required.
    – Bill Door
    Feb 10 '12 at 21:10

Any half decent compiler is going to remove that block anyway, and leave just the else block (unless it is also empty).

The point is to explain what happens when a certain important condition is met.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.