This question already has answers here:
#if vs #ifndef vs #ifdef
                                
                                    (5个答案)
                                
                        
                                去年关闭。
            
                    
我试图根据版本信息向编译器公开一个函数。

我有此版本信息。

#define LUA_VERSION_NUM     503


我只想在版本等于或小于501时包括以下函数

static void lua_len(lua_State *L, int i)
{
    //do something
}


在C ++中怎么可能?

最佳答案

#if LUA_VERSION_NUM <= 501
static void lua_len(lua_State *L, int i)
{
    //do something
}
#endif


您可能想为501以上的版本提供一个空的lua_len,以防止编译错误:

#if LUA_VERSION_NUM <= 501
static void lua_len(lua_State *L, int i)
{
    //do something
}
#else
static void lua_len(lua_State *L, int i) {}
#endif

关于c++ - 如何使编译器根据版本跳过功能? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51348793/

10-11 22:54
查看更多