Use of null statement in C

前端 未结 12 1926
挽巷
挽巷 2020-11-29 09:12

What are typical uses of null statement

;

in C ?

I know that it is basically used to skip expression where it is expected

12条回答
  •  既然无缘
    2020-11-29 09:35

    I have used it, albeit rarely, in a possibly unusual situation (and one that some/many people would find wrong). I have had to sometimes write a very complex if condition without an else clause where the if condition has to be negated. Obviously it can be something like this:

    if ( !( overly complex condition ) )
      {
      do stuff
      }
    

    It sometimes makes more sense (to me at least) to think of it in terms of positive logic. In other words, if the overly complex condition holds true, I don't want the code to run. So I have instead written it as:

    if ( overly complex condition )
      ;  // do nothing
    else
      {
      do stuff
      }  
    

提交回复
热议问题