Are there any restrictions to the C standard allowing functions to be implemented as macros?

前端 未结 2 1884
栀梦
栀梦 2021-01-18 12:50

Often, in addition to providing a function declaration, C standard headers may provide a \"masking macro\" to make things speedier. For example, if I include ctype.h<

2条回答
  •  耶瑟儿~
    2021-01-18 13:18

    From here: http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.dinkum_en_ecpp%2Flib_over.html

    Arguments that have side effects evaluate the same way whether the expression executes the macro expansion or calls the function. Macros for the functions getc and putc are explicit exceptions to this rule.

    I've found a few other references saying about the same thing (though nothing citing the C standard directly).

    So it seems the limits are that only getc() and putc() may cause havoc in the way you foresee. Apart from those two, you should be safe, assuming your platform is at least one of sane or conforming.

提交回复
热议问题