Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Header Generation    [ Add a report in this area ]  
Report #:  121713   Status: Closed
Open array declaration second param is "size", must be "high"
Project:  C++Builder Build #:  19.0.14356.6604
Version:    19.0 Submitted By:   David Berneda
Report Type:  Minor failure / Design problem Date Reported:  1/13/2014 1:52:15 AM
Severity:    Commonly encountered problem Last Updated: 4/15/2014 6:16:53 PM
Platform:    All versions Internal Tracking #:   46602
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
When dcc compiler generates the hpp header for open array params, the second parameter is named "xxx_size", but in reality it is the "xxx_high" value.

(This is somewhat confusing for people that does not know EXISTINGARRAY macro, and thinks "xxx_size" is the array count).

Docs are wrong:
http://docwiki.embarcadero.com/RADStudio/XE5/en/VCL_Compatibility_Macros
-----------
"where a is a pointer to the first element of the passed array and a_size is the number of elements."
-----------

Note:
  sysopen.h macro EXISTINGARRAY is already decrementing the array size -1

  #define EXISTINGARRAY(a) (a), ((sizeof(a)/sizeof(a[0]))-1)

Steps to Reproduce:
1. Open attached C++ project

[Unit192.pas]
--------------
unit Unit192;

interface

uses
  VCL.Dialogs, System.SysUtils;

procedure Foo(const A:Array of Integer);

implementation

// http://docwiki.embarcadero.com/RADStudio/XE5/en/VCL_Compatibility_Macros

// The Foo declaration generated by dcc32 -JPH at Unit192.hpp is:

// extern DELPHI_PACKAGE void __fastcall Foo(int const *A, const int A_Size);

// Notice second param is "int A_Size" but should be "int A_High" or similar.
// (size - 1)

procedure Foo(const A:Array of Integer);
begin
  ShowMessage(IntToStr(Length(A)));
end;

end.
--------------


2. See Unit192.hpp and Unit17.cpp code and comments

[Unit192.hpp]
--------------
...
namespace Unit192
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE void __fastcall Foo(int const *A, const int A_Size);
}
...
--------------

[Unit17.cpp]
--------------
...
#include "Unit192.hpp"
#include "sysopen.h"
...
...
void __fastcall TForm17::FormCreate(TObject *Sender)
{
  int a[10] = {1,2,3,4,5,6,7,8,9,10};

  // Typical usage:
  Foo(a,10);  // <-- second param is named "A_Size", this is confusing

  // Correct:
  Foo(EXISTINGARRAY(a));   //  Foo(a,10-1);

  // http://docwiki.embarcadero.com/RADStudio/XE5/en/VCL_Compatibility_Macros
}
--------------
Workarounds
None
Attachment
QC121713.zip
Comments

None

Server Response from: ETNACODE01