简体   繁体   English

使用C ++ 11的STLPort

[英]STLPort using C++11

I'm trying to migrate my office code from C++ to C++11 and we make heavy use of STLPorts. 我正在尝试将我的办公室代码从C ++迁移到C ++ 11,我们大量使用了STLPorts。

There's a compiler macro ( http://www.stlport.org/doc/configure.html ) - _STLP_LONG_LONG, which is used in our code and works fine in C++. 有一个编译器宏( http://www.stlport.org/doc/configure.html)-_STLP_LONG_LONG ,该宏在我们的代码中使用,并且在C ++中可以正常工作。

However, in C++ 11, this is not defined. 但是,在C ++ 11中,这没有定义。

#if defined (_STLP_LONG_LONG)
// Doesn't come here

How can I fix this? 我怎样才能解决这个问题? I tried searching on the internet but the resources are very limited. 我尝试在互联网上搜索,但资源非常有限。

Edit: Here's the code 编辑:这是代码

# if defined (_STLP_MSVC) || defined (__BORLANDC__) || defined (__ICL)
# define ULL(x) x##Ui64
typedef unsigned _STLP_LONG_LONG uint64;
# elif defined (_STLP_LONG_LONG) /// <---- Here
typedef unsigned _STLP_LONG_LONG uint64;
# define ULL(x) x##ULL
# elif defined(__MRC__) || defined(__SC__)              //*TY 02/25/2000 - added support for MPW compilers
# include "uint64.h"            //*TY 03/25/2000 - added 64bit math type definition
# else
#  error "there should be some long long type on the system!"
#  define NUMERIC_NO_64 1
# endif

As far as I can understand, the code is trying to find a long long type for the given platform. 据我了解,代码正在尝试为给定平台查找long long类型。 In case of pre C++11 on linux , g++ goes to the pointed line. 在Linux上为C ++ 11之前的版本的情况下,g ++转到了上面。 But when I execute g++ -std=c++11 ..., g++ skips this line and goes to error "there should be song long long type on the system!" 但是,当我执行g ++ -std = c ++ 11 ...时,g ++跳过了这一行,并出现错误“系统上应该有歌曲long long类型!”

It appears that STLPorts doesn't support C++11. STLPorts似乎不支持C ++ 11。

If your code requires C++11, then you don't need to use _STLP_LONG_LONG at all, since long long is standard. 如果您的代码需要C ++ 11,则根本不需要使用_STLP_LONG_LONG ,因为long long是标准的。

If your code needs to work in older C++ as well, then you can define your own macro that works with C++11 as one would expect: 如果您的代码也需要在较旧的C ++中运行,则可以定义自己的宏,该宏可以与C ++ 11一起使用:

#if __cplusplus >= 201103L
    #define MY_LONG_LONG long long
#elif defined(_STLP_LONG_LONG)
    #define MY_LONG_LONG _STLP_LONG_LONG
#endif

Of course, if your code has to work in pre-C++11 standard, then you may also need to handle the situation where the compiler doesn't provide the long long -language extension ie use #ifdef MY_LONG_LONG to check whether you can use it. 当然,如果您的代码必须在C ++ 11之前的版本中工作,那么您可能还需要处理编译器不提供long long语言扩展的情况,即使用#ifdef MY_LONG_LONG检查是否可以用它。

EDIT: For your definition, you should probably use std::int64_t instead of long long if you need a type that is 64 bits wide, as long long can technically be wider than 64 bits. 编辑:对于您的定义,如果您需要64位宽的类型,则可能应该使用std::int64_t而不是long long ,因为long long在技​​术上可以比64位宽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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