Why would somebody use an #if 1 C preprocessor directive?

前端 未结 9 2029
谎友^
谎友^ 2020-12-10 01:42

I am looking through some C source code and I don\'t understand the following part

#if 1

   typedef u         


        
相关标签:
9条回答
  • 2020-12-10 02:43

    For experimenting with various code paths.

    0 讨论(0)
  • 2020-12-10 02:43

    It's another way of saying for #if true it was most likely a result of code that was previously checking for another symbol then refactored to always be true.

    0 讨论(0)
  • 2020-12-10 02:45

    The cleaner way of doing it is probably doing something like:

    #if ALGO1
    
    #else
    
    #endif
    

    But, you will have to pass in ALGO1 to the compiler args somewhere...for example in a makefile, you need to add -DALGO1=1 (if no 1 is provided, 1 is assumed). Ref: http://www.amath.unc.edu/sysadmin/DOC4.0/c-compiler/user_guide/cc_options.doc.html

    This is more work...so, usually, for quick checks, #if 1 is used. And in some cases, forgotten and left behind as well :-)

    0 讨论(0)
提交回复
热议问题