Disable functions using MACROS

前端 未结 2 546
别跟我提以往
别跟我提以往 2021-02-10 05:09

After searching quite a bit in the Internet for a solution I decided to ask here if my solution is fine.

I\'m trying to write a simple and modular C logging library inte

2条回答
  •  有刺的猬
    2021-02-10 05:18

    Can't your disabled version simply be a constant:

    #ifndef NLOG /* NLOG not defined -> enable logging */
    int logger_init(logger_t *logger) {
    ...
    }
    #else  /* NLOG defined --> the logging system must be disabled */
    #define logger_init(logger)     0
    #endif /* NLOG */
    

    This way, you just have (after pre-compilation): result = 0; which shouldn't produce any warnings.

提交回复
热议问题