BCX Documentation Version 8.3.0, October 23, 2025

Started by Robert, October 23, 2025, 11:58:57 PM

Previous topic - Next topic

Robert

Quote from: MrBcx on October 24, 2025, 10:11:17 AMHi Robert,

The following notification in the new BCX Help file is not valid and not needed. 
I provided that information to you earlier while I was still working the problem.

"If BCX detects <iostream>, <fstream>, <vector>, or <cmath> C++ include directives
in the code, any procedures containing dynamic arrays will fail to translate correctly."

Hi MrBcx:

This has been corrected.

An new upload of the BCX Documentation is at

https://bcxbasiccoders.com/smf/index.php?topic=1424.0

MrBcx

Hi Robert,

The following notification in the new BCX Help file is not valid and not needed. 
I provided that information to you earlier while I was still working the problem.

"If BCX detects <iostream>, <fstream>, <vector>, or <cmath> C++ include directives
in the code, any procedures containing dynamic arrays will fail to translate correctly."


As a point of illustration, I borrowed one of the CPP Demos from the BCX Help (Cpp20.bas)
and incorporated my little example into the bottom of FUNCTION Main().  Like all of the Cpp Demos
that you have in the Help File, a C++ compiler is required to translate them into compilable
C++ source code.

I used BED to build this example using MINGW, MSVC, and CLANG. 

Extended_Example_cpp20.bas


#include <iostream>

CLASS bcx_vector
    PUBLIC:
    RAW AS DOUBLE x
    RAW AS DOUBLE y

    DIM CONSTRUCTOR bcx_vector (a = 0 AS DOUBLE, b = 0 AS DOUBLE)
    DIM CONSTRUCTOR bcx_vector ()

    DIM FUNCTION operator + (a AS bcx_vector) AS bcx_vector
    DIM FUNCTION operator - (a AS bcx_vector) AS bcx_vector
    DIM FUNCTION operator - () AS bcx_vector
    DIM FUNCTION operator * (a AS DOUBLE) AS bcx_vector
    DIM FUNCTION module() AS DOUBLE
    DIM SUB set_length (A  AS DOUBLE = 1)
END CLASS

CONSTRUCTOR bcx_vector::bcx_vector (a AS DOUBLE, b AS DOUBLE)
    x = a
    y = b
END CONSTRUCTOR

CONSTRUCTOR bcx_vector::bcx_vector ()
    x = 0
    y = 0
END CONSTRUCTOR

FUNCTION bcx_vector::operator + (a AS bcx_vector) AS bcx_vector
    FUNCTION = bcx_vector (x + a.x, y + a.y)
END FUNCTION

FUNCTION bcx_vector::operator - (a AS bcx_vector) AS bcx_vector
    FUNCTION = bcx_vector (x - a.x, y - a.y)
END FUNCTION

FUNCTION bcx_vector::operator - () AS bcx_vector
    FUNCTION = bcx_vector (-x, -y)
END FUNCTION

FUNCTION bcx_vector::operator * (a AS DOUBLE) AS bcx_vector
    FUNCTION = bcx_vector (x * a, y * a)
END FUNCTION

FUNCTION bcx_vector::module() AS DOUBLE
    FUNCTION = SQRT (x * x + y * y)
END FUNCTION

SUB bcx_vector::set_length (a AS DOUBLE)
    RAW AS DOUBLE length = THIS->module()
    x = x / length * a
    y = y / length * a
END SUB

FUNCTION operator << (o AS std::ostream&, a AS bcx_vector) AS std::ostream&
    o << "(" << a.x << ", " << a.y << ")";
    FUNCTION = o
END FUNCTION


FUNCTION MAIN ()
    RAW AS bcx_vector a
    RAW AS bcx_vector b
    RAW AS bcx_vector c (3, 5)

    a = c * 3
    a = b + c
    c = b - c + a + (b - a) * 7
    c = -c

    std::cout << "The module of bcx_vector c: " << c.module() << std::endl

    std::cout << "The content of bcx_vector a: " << a << std::endl
    std::cout << "The opposite of bcx_vector a: " << -a << std::endl

    c.set_length(2)        ' Transforms c in a bcx_vector of size 2.

    a = bcx_vector (56, -3)
    b = bcx_vector (7, c.y)

    b.set_length()          ' Transforms b in an unitary bcx_vector.

    std::cout << "The content of bcx_vector b: " << b << std::endl

    DIM AS DOUBLE k
    k = bcx_vector(1, 1).module()  ' k will contain 1.4142.
    std::cout << "k contains: " << k << std::endl

    '*************************************************************************
    '                      Demonstrate Extended Example
    '*************************************************************************
   
    PRINT "*******************************************************************"
    PRINT TestFunc$("Everything is possible")
    PRINT TestFunc2 (PI)
    PAUSE
END FUNCTION



FUNCTION TestFunc$ (MyArg$)
    DIM DYNAMIC DynArray1$ [10, 10]
    DIM DYNAMIC DynArray2$ [10, 10]
    DIM DYNAMIC DynArray3$ [10, 10]
    DynArray1$[5, 5] = MyArg$
    FUNCTION = DynArray1$[5, 5]
END FUNCTION


FUNCTION TestFunc2 (TheOne AS DOUBLE) AS DOUBLE
    DIM DYNAMIC DynArray[10, 10] AS DOUBLE
    DynArray[5, 5] = TheOne
    FUNCTION = DynArray[5, 5] + 1 + 2 + 3
END FUNCTION



OUTPUT:

The module of bcx_vector c: 40.8167
The content of bcx_vector a: (3, 5)
The opposite of bcx_vector a: (-3, -5)
The content of bcx_vector b: (0.971275, 0.23796)
k contains: 1.41421
*******************************************************************
Everything is possible
 9.14159265358979

Press any key to continue . . .


BCX 8.3.0 correctly translates those additions as :



int main ()
{
  bcx_vector  a;
  bcx_vector  b;
  bcx_vector  c(3,5);
  a=c*3;
  a=b+c;
  c=b-c+a+(b-a)*7;
  c=-c;
  std::cout << "The module of bcx_vector c: "<<c.module() << std::endl;
  std::cout << "The content of bcx_vector a: "<<a << std::endl;
  std::cout << "The opposite of bcx_vector a: "<<-a << std::endl;
  c.set_length(2);
  a=bcx_vector(56,-3);
  b=bcx_vector(7,c.y);
  b.set_length();
  std::cout << "The content of bcx_vector b: "<<b << std::endl;
  double  k={0};
  k=bcx_vector(1,1).module();
  std::cout << "k contains: "<<k << std::endl;
  printf("%s\n","*******************************************************************");
  printf("%s\n",TestFunc("Everything is possible"));
  printf("% .15G \n",(double)TestFunc2(3.141592653589793));
  Pause();
}



char * TestFunc (char* MyArg)
{
  char  *BCX_RetStr={0};
  char  ***DynArray1=0;
  {
  size_t dimensions[3] = {(size_t)10, (size_t)10, (size_t)BCXSTRSIZE};
  DynArray1= (char***)CreateArr (DynArray1,sizeof(char),0,3, dimensions);
  }
  char  ***DynArray2=0;
  {
  size_t dimensions[3] = {(size_t)10, (size_t)10, (size_t)BCXSTRSIZE};
  DynArray2= (char***)CreateArr (DynArray2,sizeof(char),0,3, dimensions);
  }
  char  ***DynArray3=0;
  {
  size_t dimensions[3] = {(size_t)10, (size_t)10, (size_t)BCXSTRSIZE};
  DynArray3= (char***)CreateArr (DynArray3,sizeof(char),0,3, dimensions);
  }
  strcpy(DynArray1[5][5],MyArg);
  BCX_RetStr = BCX_TempStr(strlen(DynArray1[5][5]));
  strcpy(BCX_RetStr,DynArray1[5][5]);

  if (DynArray3) DestroyArr((void **)DynArray3, 3, 1);
  if (DynArray2) DestroyArr((void **)DynArray2, 3, 1);
  if (DynArray1) DestroyArr((void **)DynArray1, 3, 1);

  return BCX_RetStr;
}



double TestFunc2 (double TheOne)
{
  double  **DynArray=0;
  {
  size_t dimensions[2] = {(size_t)10, (size_t)10};
  DynArray= (double**)CreateArr (DynArray,sizeof(double),0,2, dimensions);
  }
  double  Bcx_RetVal={0};
  DynArray[5][5]=TheOne;
  Bcx_RetVal=DynArray[5][5]+1+2+3;
  if (DynArray) { DestroyArr((void **)DynArray, 2, 1); DynArray=NULL; }
  return Bcx_RetVal;
}




jbk


Robert

BCX Documentation Version 8.3.0, October 23, 2025

REVISIONS

Kevin Diggins
🔗 replaced the $TRACE directive example.

🔗 in the DYNAMIC arrays section, consolidated the STRING and NON-STRING examples demonstrating the freeing of memory of LOCAL DYNAMIC arrays in a SUB or FUNCTION procedure.

🔗 in the BCXFONT handle example, within the $CCODE directives block, corrected casing on BCX system variables BCX_HINSTANCE, BCX_SCALEX, and BCX_SCALEY which were in all upper case instead of the mixed case, BCX_hInstance, BCX_ScaleX, and BCX_ScaleY expected by the C compiler. The BCXFONT handle example could not be compiled because BCX takes a hands-off approach to anything wrapped in $CCODE tags. If that function was written in plain BCX BASIC, BCX would convert those variables to their proper case spellings during translation.

Robert Wishlaw
🔗 added the Result: to the example in the $CCODE FUNCSUB, section and, as well, the two examples in the $CPROTO directives section.

🔗 revised the BCX_THREADWAIT statement example. The location of the SLEEP statements had to be changed and more SLEEP statements had to be added on the exit of each thread to keep the colors in correct synchronization with the thread.

🔗 revised the $TRACE directive Purpose: description, adding that $TRACE will work only within FUNCTION and SUB procedures.

🔗 revised the DYNAMIC arrays section.

🔗 revised the IMOD section, adding documentation for the use of IMOD as operator.

🔗 repositioned the BEGINBLOCK ... ENDBLOCK statements section and added images of the code execution Result:.

 

SHA-256
982A173AD535E6AF2803A32253F462399E1F21B32FC48D215DAFD57235E64D75