首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何消除未定义预编译器定义的警告

如何消除未定义预编译器定义的警告
EN

Stack Overflow用户
提问于 2022-01-06 14:07:28
回答 1查看 243关注 0票数 2

有一个文件是我从联合网站下载的

代码语言:javascript
复制
#pragma once

// Standard base includes, defines that indicate our current platform, etc.

#include <stddef.h>


// Which platform we are on?
// UNITY_WIN - Windows (regular win32)
// UNITY_OSX - Mac OS X
// UNITY_LINUX - Linux
// UNITY_IOS - iOS
// UNITY_TVOS - tvOS
// UNITY_ANDROID - Android
// UNITY_METRO - WSA or UWP
// UNITY_WEBGL - WebGL

#if _MSC_VER
    #define UNITY_WIN 1
#elif defined(__APPLE__)
    #if TARGET_OS_TV //'TARGET_OS_TV' is not defined, evaluates to 0
        #define UNITY_TVOS 1
    #elif TARGET_OS_IOS //'TARGET_OS_IOS' is not defined, evaluates to 0
        #define UNITY_IOS 1
    #else
        #define UNITY_OSX 1 //'UNITY_OSX' macro redefined
    #endif
#elif defined(__ANDROID__)
    #define UNITY_ANDROID 1
#elif defined(UNITY_METRO) || defined(UNITY_LINUX) || defined(UNITY_WEBGL)
    // these are defined externally
#elif defined(__EMSCRIPTEN__)
    // this is already defined in Unity 5.6
    #define UNITY_WEBGL 1
#else
    #error "Unknown platform!"
#endif

...

问题是,当我试图将文件包含在我的XCode项目中时,我收到了一个警告(将它们放在注释中)。

代码语言:javascript
复制
...
    #if TARGET_OS_TV //'TARGET_OS_TV' is not defined, evaluates to 0
        #define UNITY_TVOS 1
    #elif TARGET_OS_IOS //'TARGET_OS_IOS' is not defined, evaluates to 0
        #define UNITY_IOS 1
    #else
        #define UNITY_OSX 1 //'UNITY_OSX' macro redefined
    #endif
...

我试着使用#pragma warning(suppress: 4101)和一些类似的方法,但是没有用

UPD

代码语言:javascript
复制
...
#ifdef TARGET_OS_TV
        #define UNITY_TVOS 1
    #elif TARGET_OS_IOS //'TARGET_OS_IOS' is not defined, evaluates to 0
        #define UNITY_IOS 1
    #else
        #define UNITY_OSX 1 
    #endif
...

使用ifdef有助于消除第一个警告,但第二个警告仍然有效。

UPD2

代码语言:javascript
复制
...
    #ifdef TARGET_OS_TV
        #define UNITY_TVOS 1
    #elifdef TARGET_OS_IOS //Invalid preprocessing directive
        #define UNITY_IOS 1
    #else
        #define UNITY_OSX 1
    #endif
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-06 14:11:39

不应使用#if测试未定义的宏。该警告意味着您应该使用#ifdef代替。

您可能无法定义先前定义的宏。您可以首先不定义旧的定义,但这很少是一个好主意。

使用ifdef的

有助于消除第一个警告,但第二个警告仍然有效。

在c++23中,您将能够使用#elifdef

否则,您可以使用#elif defined(the_macro)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70608353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档