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
?
CodePudding user response:
How do I get the compiler to output
Infinity
(orHUGE_VAL
) to the.hpp
file instead ofINF
?
AFAIK, you don't. That is simply how the Delphi compiler chose to translate Infinity
for C . Feel free to submit a bug report to Embarcadero about it.
In the meantime, as a workaround, what you could try instead is declaring GetJSONDouble
with {$NODEFINE}
or {$EXTERNALSYM}
to avoid the Delphi compiler from outputting a default declaration in the .hpp
, and then use {$HPPEMIT}
to declare GetJSONDouble()
yourself, eg:
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.