Static array parameter

Top  Previous  Next

What is translated > Types > Arrays > Array parameters > Static array parameter

 

A static array is passed to functions as an open array parameter. The additional second parameter for the upper bound of the array is inserted into the declaration of the function automatically and is passed to the function automatically too. The upper bound of the array is calculated by means of a macro:

 

#define MAXIDX(x) (sizeof(x)/sizeof(x[0]))-1

 

 

procedure foo(Arr: Array of Char);

 

procedure bar();

var

   chararray : Array [1..10] of Char;

begin

    foo(chararray);

end;

 

is translated to:

 

C++Builder                                                                Other                                                                                                                                                                                                                                                                                                                      

                                                                                                                                                                                                                                                                                                                                                                                     

void __fastcall Foo(const Char* Arr, int Arr_maxidx)      void Foo(const std::vector<Char> Arr)                                                                                                                                                                                                                                                                                      

{                                                                               {                                                                                                                                                                                                                                                                                                                          

}                                                                               }                                                                                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                                                                                                                                     

void __fastcall bar()                                                    void bar()                                                                                                                                                                                                                                                                                                                 

{                                                                               {                                                                                                                                                                                                                                                                                                                          

  Char chararray[10/*# range 1..10*/];                             Char chararray[10/*# range 1..10*/];                                                                                                                                                                                                                                                                                     

  Foo(OpenArrayEx<Char>(chararray, 10), 9);                                                                                                                                                                                                                                                                                                                                          

}                                                                                 std::vector<Char> test__0(chararray, chararray + 10 - 1 + 1);                                                                                                                                                                                                                                                            

                                                                                  Foo(test__0);                                                                                                                                                                                                                                                                                                            

                                                                               }                                                                                                                                                                                                                                                                                                                          

                                                                                                                                                                                                                                                                                                                                                                                     

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content