在Mingw中使用#elif [英] Use of #elif in mingw

查看:118
本文介绍了在Mingw中使用#elif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将某些代码从Visual Studio移植到mingw,显然以下代码在Visual Studio中似乎可以运行,但在Mingw中失败

I am currently porting some code from Visual studio to mingw and apparently the following code seems to work in Visual Studio but fails in Mingw

#if defined(BATCH_TRIANGLESTRIP)
static const size_t VERT_COUNT = 4;
#elif defined(BATCH_TRIANGLELIST)
static const size_t VERT_COUNT = 6;
#elif //error here on mingw
#error BATCH_TRIANGLESTRIP or BATCH_TRIANGLELIST need to be defined
#endif

我的问题是最后一个#elif,我查看了的文档msdn ,显然他们没有条件的#elif语句.我想知道mingw中的上述代码是否等效

My question is with the last #elif I looked over at the documentation of msdn and apparently they dont have a #elif statement without a condition. I wanted to know will the equivalent of above code in mingw be

 #if defined(BATCH_TRIANGLESTRIP)
    static const size_t VERT_COUNT = 4; 
    #elif defined(BATCH_TRIANGLELIST)
    static const size_t VERT_COUNT = 6; 
    #else
    #error BATCH_TRIANGLESTRIP or BATCH_TRIANGLELIST need to be defined
    #endif

这是我用原始代码得到的错误

This is the error I get with the original code

error: #elif with no expression

推荐答案

#elif需要根据C ++标准(以及C标准)的常量表达式.无法诊断裸#elif是Visual Studio中的错误.

#elif requires a constant expression according to the C++ standard (and the C standard as well). The failure to diagnose a bare #elif is a bug in Visual Studio.

标准C ++中的等效项将使用#else而不是#elif. Visual Studio和MinGW都应正确处理此问题-任何符合要求的编译器也应正确处理.

The equivalent in standard C++ would use #else rather than #elif. Both Visual Studio and MinGW should handle that correctly -- as should any conforming compiler.

这篇关于在Mingw中使用#elif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆