Add my own compiler warning

前端 未结 5 1426
庸人自扰
庸人自扰 2021-01-03 19:20

When using sprintf, the compiler warns me that the function is deprecated.

How can I show my own compiler warning?

5条回答
  •  无人及你
    2021-01-03 19:33

    Although there is no standard #warning directice, many compilers (including GCC, VC, Intels and Apples), support #warning message.

    #warning "this is deprecated"
    

    Often it is better to not only bring up a warning (which people can overlook), but to let compiling fail completely, using the #error directive (which is standard):

    #if !defined(FOO) && !defined(BAR)
    #  error "you have neither foo nor bar set up"
    #endif
    

提交回复
热议问题