코드 테스트

잡다지식2007. 9. 18. 10:47
728x90
  • Use #if 0 rather than comments to temporarily kill blocks of code.

    Non-portable example:

      int
      foo()
      {
        ...
        a = b + c;
        /*
         * Not doing this right now.
        a += 87;
        if (a > b) (* have to check for the
                      candy factor *)
          c++;
         */
        ...
      }
    

    This is a bad idea, because you always end up wanting to kill code blocks that include comments already. No, you can't rely on comments nesting properly. That's far from portable. You have to do something crazy like changing /**/ pairs to (**) pairs. You'll forget. And don't try using #ifdef NOTUSED, the day you do that, the next day someone will quietly start defining NOTUSED somewhere. It's much better to block the code out with a #if 0, #endif pair, and a good comment at the top. Of course, this kind of thing should always be a temporary thing, unless the blocked out code fulfills some amazing documentation purpose.

    Portable example:

      int
      foo()
      {
        ...
        a = b + c;
      #if 0
        /* Not doing this right now. */
        a += 87;
        if (a > b) /* have to check for the
                      candy factor */
          c++;
      #endif
        ...
      }
    


  • #if 0
    
    /* excluded */
    
    #else
    
    /* included */
    
    #endif



    3개 이상 일때.~~





    #define FLAG 2 #if FLAG == 0 printf("FLAG is 0"); #endif #if FLAG == 1 printf("FLAG is 1"); #endif #if FLAG == 2 printf("FLAG is 2"); #endif


    그냥 블럭처리가 편해서 그냥 쓰는데 이렇게 쓰도록 하자는 의미에서...ㅋㅋ









    728x90

    작성자

    Posted by 일퍼센트

    관련 글

    댓글 영역