Why allow concatenation of string literals?

前端 未结 10 633
借酒劲吻你
借酒劲吻你 2020-11-30 14:47

I was recently bitten by a subtle bug.

char ** int2str = {
   \"zero\", // 0
   \"one\",  // 1
   \"two\"   // 2
   \"three\",// 3
   nullptr };

assert( int         


        
10条回答
  •  离开以前
    2020-11-30 15:28

    It's a great feature that allows you to combine preprocessor strings with your strings.

    // Here we define the correct printf modifier for time_t
    #ifdef TIME_T_LONG
        #define TIME_T_MOD "l"
    #elif defined(TIME_T_LONG_LONG)
        #define TIME_T_MOD "ll"
    #else
        #define TIME_T_MOD ""
    #endif
    
    // And he we merge the modifier into the rest of our format string
    printf("time is %" TIME_T_MOD "u\n", time(0));
    

提交回复
热议问题