运行limits例程,在bcc5.6下出错……

kingofark 2002-10-25 12:16:44
运行《C++标准程式库》p64 的limits1.cpp
在vc7下正常,在bcc5.6(bcb6)下出错。

//limits1.cpp
/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <iostream>
#include <limits>
#include <string>
using namespace std;

int main()
{
// use textual representation for bool
cout << boolalpha;

// print maximum of integral types
cout << "max(short): " << numeric_limits<short>::max() << endl;
cout << "max(int): " << numeric_limits<int>::max() << endl;
cout << "max(long): " << numeric_limits<long>::max() << endl;
cout << endl;

// print maximum of floating-point types
cout << "max(float): "
<< numeric_limits<float>::max() << endl;
cout << "max(double): "
<< numeric_limits<double>::max() << endl;
cout << "max(long double): "
<< numeric_limits<long double>::max() << endl; // 注意!这里出错!!
cout << endl;

// print whether char is signed
cout << "is_signed(char): "
<< numeric_limits<char>::is_signed << endl;
cout << endl;

// print whether numeric limits for type string exist
cout << "is_specialized(string): "
<< numeric_limits<string>::is_specialized << endl;
}
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu_feng_fly 2002-10-25
  • 打赏
  • 举报
回复
报什么错啊?
kingofark 2002-10-25
  • 打赏
  • 举报
回复
《C++标准程式库》
p64的util/limits1.cpp范例运行情况:
WinXP/PIII733/256Mb 环境变量为vs.net和bcb6的缺省安装设置

VC7[o], BCB6[x]

BCB6运行到

cout << "max(long double): "
<< numeric_limits<long double>::max() << endl;

的时候,弹出讯息:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOverflow with message 'Floating point overflow'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------


[VC7的场合]

在VC7中,numeric_limits<long double>::max()用 return LDBL_MAX;作返回,而在float.h中有

#define DBL_MAX 1.7976931348623158e+308 /* max value */
以及
#define LDBL_MAX DBL_MAX /* max value */


[bcb6的场合]

在BCB6中,numeric_limits<long double>::max()也用 return LDBL_MAX;作返回,而在float.h中有

#define LDBL_MAX std::_max_ldble
以及
extern long double _RTLENTRY _EXPDATA _max_ldble;

当然,不排除我自己机子设置等等意外情况。
fangrk 2002-10-25
  • 打赏
  • 举报
回复
我用Borland C++ Builder 5运行,没问题!

max(short): 32767
max(int): 2147483647
max(long): 2147483647

max(float): 3.40282e+38
max(double): 1.79769e+308
max(long double): 1.18973e+4932

is_signed(char): true

is_specialized(string): false

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧