Delphi 单位中的无穷大在 .hpp 文件中转换为 +INF
Infinity in Delphi unit is translated to +INF in .hpp file
我正在使用 C++Builder XE6 并编写了以下 Delphi 单元:
unit JSONUtils;
interface
uses
System.JSON, System.Math;
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double = Infinity): Double;
implementation
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double): Double;
begin
Result := Value.GetValue<Double>(Path, Default);
end;
end.
编译后生成如下.hpp文件:
// CodeGear C++Builder
// Copyright (c) 1995, 2014 by Embarcadero Technologies, Inc.
// All rights reserved
// (DO NOT EDIT: machine generated header) 'JSONUtils.pas' rev: 27.00 (Windows)
#ifndef JsonutilsHPP
#define JsonutilsHPP
#pragma delphiheader begin
#pragma option push
#pragma option -w- // All warnings off
#pragma option -Vx // Zero-length empty class member
#pragma pack(push,8)
#include <System.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.JSON.hpp> // Pascal unit
#include <System.Math.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Jsonutils
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE double __fastcall GetJSONDouble(System::Json::TJSONValue* Value, System::UnicodeString Path, double Default = +INF);
} /* namespace Jsonutils */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_JSONUTILS)
using namespace Jsonutils;
#endif
#pragma pack(pop)
#pragma option pop
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // JsonutilsHPP
请注意,.pas
文件中 Infinity
的默认值在 .hpp
文件中转换为 +INF
。
当我在 C++ 单元中包含 .hpp
文件时,出现以下编译器错误:
[bcc32 Error] JSONUtils.hpp(26): E2451 Undefined symbol 'INF'
可以理解,因为INF
在System.Math.hpp
中没有定义,而Infinity
是。
如何让编译器将 Infinity
(或 HUGE_VAL
)输出到 .hpp
文件而不是 +INF
?
How do I get the compiler to output Infinity
(or HUGE_VAL
) to the .hpp
file instead of +INF
?
AFAIK,你不知道。这就是 Delphi 编译器选择为 C++ 翻译 Infinity
的方式。随意 submit a bug report to Embarcadero 关于它。
同时,作为一种解决方法,您可以尝试用 {$NODEFINE}
or {$EXTERNALSYM}
to avoid the Delphi compiler from outputting a default declaration in the .hpp
, and then use {$HPPEMIT}
声明 GetJSONDouble
来自己声明 GetJSONDouble()
,例如:
unit JSONUtils;
interface
uses
System.JSON, System.Math;
{$EXTERNALSYM GetJSONDouble}
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double = Infinity): Double;
{$HPPEMIT OPENNAMESPACE}
{$HPPEMIT 'extern DELPHI_PACKAGE double __fastcall GetJSONDouble(System::Json::TJSONValue* Value, System::UnicodeString Path, double Default = System::Math::Infinity);'}
{$HPPEMIT CLOSENAMESPACE}
implementation
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double): Double;
begin
Result := Value.GetValue<Double>(Path, Default);
end;
end.
我正在使用 C++Builder XE6 并编写了以下 Delphi 单元:
unit JSONUtils;
interface
uses
System.JSON, System.Math;
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double = Infinity): Double;
implementation
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double): Double;
begin
Result := Value.GetValue<Double>(Path, Default);
end;
end.
编译后生成如下.hpp文件:
// CodeGear C++Builder
// Copyright (c) 1995, 2014 by Embarcadero Technologies, Inc.
// All rights reserved
// (DO NOT EDIT: machine generated header) 'JSONUtils.pas' rev: 27.00 (Windows)
#ifndef JsonutilsHPP
#define JsonutilsHPP
#pragma delphiheader begin
#pragma option push
#pragma option -w- // All warnings off
#pragma option -Vx // Zero-length empty class member
#pragma pack(push,8)
#include <System.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.JSON.hpp> // Pascal unit
#include <System.Math.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Jsonutils
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE double __fastcall GetJSONDouble(System::Json::TJSONValue* Value, System::UnicodeString Path, double Default = +INF);
} /* namespace Jsonutils */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_JSONUTILS)
using namespace Jsonutils;
#endif
#pragma pack(pop)
#pragma option pop
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // JsonutilsHPP
请注意,.pas
文件中 Infinity
的默认值在 .hpp
文件中转换为 +INF
。
当我在 C++ 单元中包含 .hpp
文件时,出现以下编译器错误:
[bcc32 Error] JSONUtils.hpp(26): E2451 Undefined symbol 'INF'
可以理解,因为INF
在System.Math.hpp
中没有定义,而Infinity
是。
如何让编译器将 Infinity
(或 HUGE_VAL
)输出到 .hpp
文件而不是 +INF
?
How do I get the compiler to output
Infinity
(orHUGE_VAL
) to the.hpp
file instead of+INF
?
AFAIK,你不知道。这就是 Delphi 编译器选择为 C++ 翻译 Infinity
的方式。随意 submit a bug report to Embarcadero 关于它。
同时,作为一种解决方法,您可以尝试用 {$NODEFINE}
or {$EXTERNALSYM}
to avoid the Delphi compiler from outputting a default declaration in the .hpp
, and then use {$HPPEMIT}
声明 GetJSONDouble
来自己声明 GetJSONDouble()
,例如:
unit JSONUtils;
interface
uses
System.JSON, System.Math;
{$EXTERNALSYM GetJSONDouble}
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double = Infinity): Double;
{$HPPEMIT OPENNAMESPACE}
{$HPPEMIT 'extern DELPHI_PACKAGE double __fastcall GetJSONDouble(System::Json::TJSONValue* Value, System::UnicodeString Path, double Default = System::Math::Infinity);'}
{$HPPEMIT CLOSENAMESPACE}
implementation
function GetJSONDouble (Value: TJSONValue; Path: string; Default: Double): Double;
begin
Result := Value.GetValue<Double>(Path, Default);
end;
end.