简体   繁体   中英

Conditionally defining C function macros

I am wondering how I can conditionally define function macros. For instance, suppose I have a function macro called SETBIT . I would like to define my own version of it should someone using my library not include a separate header file where such a macro function would have already been defined. The reason for this is portability among different compilers.

So, I know that I can do this with constants as follows:

#ifndef X
#define X 10
#endif

I would like to do something similar with a function macro

#ifndef SETBIT
#define SETBIT(port,bit) ((port) |= (1 << (bit)))
#endif

However, I don't believe this will work.

However, I don't believe this will work.

What leads you to believe that? It will work (provided that you fix the typo - it should read #ifndef SET_BIT , I suppose).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM