Watch, Follow, &
Connect with Us

Please visit our new home

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
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:
"where a is a pointer to the first element of the passed array and a_size is the number of elements."

  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

unit Unit192;


  VCL.Dialogs, System.SysUtils;

procedure Foo(const A:Array of Integer);



// 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);


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

namespace Unit192
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern DELPHI_PACKAGE void __fastcall Foo(int const *A, const int A_Size);

#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);



Server Response from: ETNACODE01