I'm using C++Builder XE6 and wrote the following Delphi unit:
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.
When compiled, the following .hpp file is generated:
// 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
Note that the default value of Infinity in the .pas file is translated to +INF in the .hpp file.
When I include the .hpp file in a C++ unit, I get the following compiler error:
[bcc32 Error] JSONUtils.hpp(26): E2451 Undefined symbol 'INF'
Understandable, because INF is not defined in System.Math.hpp, but Infinity is.
How do I get the compiler to output Infinity (or HUGE_VAL) to the .hpp file instead of +INF?
double X = Infinity, Y = HUGE_VAL;, the comparison(X == Y)evaluates totrue. Both X and Y contain the value0x7FF0000000000000.