Compilation Directives


$COMPILER directive

Purpose:

Directive to invoke a compiler.

Syntax:

$COMPILER "StringLiteralDirective"

Parameters:

  • Data type: STRING
    "StringLiteralDirective" Path and name of compiler and command line arguments.

Example:

$IPRINT_OFF

$COMPILER "$PELLES$\Bin\pocc.exe -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"

Using the Pelles C Compiler driver, cc.exe, the following example, when placed at the beginning of the code for a DLL, will compile and link automatically when the bc.exe translator has finished translating the code file.

Example:

$IPRINT_OFF

$COMPILER "$PELLES$\Bin\cc.exe -W1 -Gz -Ze -Zx -Go -Tx64-coff $FILE$.c -release -machine:X64 -subsystem:windows -dll"

$LINKER directive

Purpose:

Directive to invoke a linker.

Syntax:

$LINKER "StringLiteralDirective"

Parameters:

  • Data type: STRING
    "StringLiteralDirective" Path and name of linker and command line arguments.

Example:

Windows mode

$IPRINT_OFF

$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:windows _
             -OUT:$FILE$.exe _
                  $FILE$.obj "

Example:

Console mode

$IPRINT_OFF

$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:console _
             -OUT:$FILE$.exe _
                  $FILE$.obj "

$ONENTRY directive

Purpose:

Directive to perform functions after BCX translation but before any $COMPILER, $LINKER, $RESOURCE, or $ONEXIT directives.

Syntax:

$ONENTRY "StringLiteralDirective"

Parameters:

  • Data type: STRING
    "StringLiteralDirective" The function to perform or command to execute after BCX translation and before the C compiler runs.

Example:

$ONENTRY "echo Starting to compile $file$"

$ONEXIT directive

Purpose:

Directive to perform functions after BCX translation and after any $COMPILER, $LINKER, $RESOURCE, or $ONENTRY directives.

Syntax:

$ONEXIT "StringLiteralDirective"

Parameters:

  • Data type: STRING
    "StringLiteralDirective" The function to perform or command to execute after the C compiler has completed compilation.

Example:

$ONEXIT "echo Completed compiling the C translation of $FILE$"

$BCX$ macro substitute

Purpose:

$BCX$ is a replaceable macro substitute for the path to the \bin\ directory containing the BC.EXE file.

👉 The $BCX$ macro can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY and $ONEXIT directives.

Syntax:

$BCX$

Parameters:

  • None

Remarks:

This path is derived from the Registry entry made during the BCX installation process and includes a trailing backslash.

If the \bin\ directory has been moved since the installation then this macro will not function properly. To correct the Registry entry after such a move run the BCX translator with the -r switch.

BC -r

To determine, for certain, the value which would be returned by the $BCX$ macro, run the following one line program.

PRINT BCXPATH$

$FILE$ macro substitute

Purpose:

$FILE$ is a self-referencing substitute for the file name without the extension. For example, if the file name is ThisFile.bas, $FILE$ will substitute ThisFile.

$FILE$ can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY and $ONEXIT directives.

Syntax:

$FILE$

Parameters:

  • None

$PELLES$ macro substitute

Purpose:

$PELLES$ is a replaceable macro substitute for the root path, including a trailing backslash, of the Pelles C installation. The root path is derived from the Registry entry made by the Pelles C installation process. If the Pelles C directory has been moved since the installation then this macro will not function properly.

To determine for certain the value which would be returned by the $PELLES$ macro, run the following one line program.

PRINT PELLESPATH$

The $PELLES$ macro can be used only with the $COMPILER, $LINKER, $RESOURCE, $ONENTRY, and $ONEXIT directives.

Syntax:

$PELLES$

Parameters:

  • None

$WARNINGS_OFF and $WARNINGS_ON directives

👉 The $WARNINGS directive, functionally equivalent to the $WARNINGS_ON directive is deprecated.

Purpose:

BCX emits, in the C translation, a number of #pragma statements which can disable some C/C++ compilation warnings.

The $WARNINGS_OFF directive suppresses the C/C++ compiler warnings specified in the #pragma statements. This is the default when neither warning directive is used.

The $WARNINGS_ON directive does not suppress any warnings. The compiler will issue warnings according to the warning level options that are set.

The BCX command line option -w will activate the $WARNINGS_ON directive, allowing C/C++ compiler warnings as well as activating BCX BASIC translation warnings.

Remarks:

$WARNINGS_ON or $WARNINGS_OFF should be used only one time, preferably near the top of the code.
It's an all or nothing directive.
That said, $WARNINGS_ON can be left enabled, and selective warnings can be disabled by placing them in the header section, like so:

$WARNINGS_ON
 
$HEADER
#pragma warning(disable: 4244) // conversion from type1 to type2 warnings
$HEADER

$LEANANDMEAN directive

Purpose:

The $LEANANDMEAN directive is a wrapper for the Win32 API WIN32_LEAN_AND_MEAN define. When $LEANANDMEAN is used, some header files are excluded by windows.h including the OLE, RPC, and network headers.


$BCXVERSION directive

Purpose:

The $BCXVERSION directive can be used to specify the minimum version of the BCX translator required to translate the program.

The $BCXVERSION directive is placed at top of source file and if the BCX version is less than that specified by the directive, BCX will abort with a message that the translator must be updated. If the BCX version is equal to or greater than that specified by the directive, a statement is emitted stating the version of the translator specified in the $BCXVERSION directive.

Syntax:

$BCXVERSION "Version String"

Parameters:

  • Data type: STRING
    "Version String" Version number of the BCX translator.

Example:

The following will abort code translation if the BCX version is prior to 3.82a.

$BCXVERSION "3.82a"

BCX_VERSION$ variable

Purpose:

BCX_VERSION$ can be used to retrieve the version of the BCX translator that was used when the program was translated.

Syntax:

RetStr = BCX_VERSION$

Return Value:

  • Data type: STRING
    RetStr Specifies the version of the BCX translator that was used when the program was translated.

Parameters:

  • None

Example 1:

This example will return the version of the BCX translator that was used when the example was translated.

DIM RetStr$

RetStr$ = BCX_VERSION$

PRINT RetStr$

Resource Compilation Directives


$RESOURCE directive

Purpose:

Directive to invoke a resource compiler. If the $LINKER directive is used then the $RESOURCE directive must be placed before the $LINKER directive.

Syntax:

$RESOURCE "ResourceCompiler" ["ResourceFile.rc"]

Parameters:

  • Data type: STRING
    "ResourceCompiler" String literal path and name of resource compiler.
  • Data type: STRING
    "ResourceFile.rc" [OPTIONAL] String literal path and name of a .rc resource file. This .rc file will be compiled to a .res file by the ResourceCompiler.

    If a .rc file is specified and the BCX_RESOURCE statement is used to add inline resources, BCX will concatenate the inline BCX_RESOURCE statements to the end of the specified .rc resource file. The consolidated .rc file will be compiled to a .res file by the ResourceCompiler.

    If a .rc file is not specified then the BCX_RESOURCE statement will be used by the programmer to add inline resources. BCX will write the BCX_RESOURCE statements to a new file named $FILE$__.rc which will be compiled to a .res file by the ResourceCompiler.

    👉 Please note that the internal processing by the BCX translator requires that the maximum length of any one line in the .rc file must be less than 2048 characters.

Example:

$IPRINT_OFF

$RESOURCE "$PELLES$\bin\porc.exe" "Resource.rc"

BCX_RESOURCE statement

Purpose:

This statement is used to inline statements which would usually be placed in an .rc resource file.

If the BCX_RESOURCE statement is used without a prior $RESOURCE directive, a file named $FILE$__.rc is created in the default directory. In this case the $FILE$__.rc file is not compiled.

If a .rc resource file has been specified as a parameter in the $RESOURCE directive, the specified .rc file is copied to a new file named $FILE$__.rc to which the BCX_RESOURCE statements are concatenated. The $FILE$__.rc file is then compiled into a .res file. If the $LINKER directive is used after the $RESOURCE directive, the resulting .res file is also linked into the .exe file.

Syntax:

BCX_RESOURCE .rc format statement

Parameters:

  • Data type: STRING
    .rc format statement Any valid .rc file statement.

Example:

Save the example code below as test64.bas.
Click here to download a .zip file containing an icon file and a .bmp file named, respectively, "smiley.ico" and "smiley.bmp".
Unpack the smiley.zip into the same directory as test64.bas.
Save, as Build.bat, the batch file following the test64.bas code into the same directory as test64.bas.
Run Build.bat to compile.

GUI "BCX_RESOURCE", ICON, 1234

$IPRINT_OFF

$RESOURCE "$PELLES$\bin\porc.exe"

$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"

$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:windows _
                  $FILE$.obj _
             -OUT:$FILE$.exe"

BCX_RESOURCE 1234 ICON "smiley.ico"

SUB FORMLOAD
GLOBAL Form1 AS HWND
Form1 = BCX_FORM("BCX_RESOURCE", 0, 0, 150, 153)
BCX_SET_FORM_COLOR(Form1,QBCOLOR(31))
GLOBAL hCtl AS CONTROL
hCtl = BCX_BMPBUTTON("smiley.bmp", _
                            Form1, _
                             5678, _
                                9, _
                                9, _
                                0, _
                                0)
CENTER(Form1)
SHOW(Form1)
END SUB

BEGIN EVENTS
SELECT CASE CBMSG
  CASE WM_CLOSE
  DestroyWindow(Form1)
  EXIT FUNCTION

END SELECT
END EVENTS

Build.bat compilation batch file:

CALL povars64.bat
bc test64

$BCX_RESOURCE directive

Purpose:

The $BCX_RESOURCE directive performs the same function as the BCX_RESOURCE statement above but it is used to bracket a block of resource statements. A $BCX_RESOURCE directive is placed before and after the resource statements.

Syntax:

$BCX_RESOURCE
 /** Resource statements go here */
$BCX_RESOURCE

Example:

Save the example code below as test64.bas.
Save, as Build.bat, the batch file following the test64.bas code into the same directory as test64.bas.
Run Build.bat to compile.

$IPRINT_OFF

$RESOURCE "$PELLES$\Bin\porc.exe"

$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"

$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:windows _
             -OUT:$FILE$.exe _
                  $FILE$.obj _
                $FILE$__.res"
 
$BCX_RESOURCE
#define ID_MAINMENU      102
#define ID_FILE_EXIT   40001
#define ID_FILE_OPEN   40002
#define ID_FILE_SAVEAS 40003
#define ID_FILE_NEW    40004
#define ID_HELP        40005
#define ID_ABOUT       40006

ID_MAINMENU MENU DISCARDABLE
BEGIN
 POPUP "&File"
  BEGIN
   MENUITEM "&Open File" ID_FILE_OPEN
   MENUITEM "&New file"  ID_FILE_NEW
   MENUITEM "Save &As"   ID_FILE_SAVEAS
   MENUITEM SEPARATOR
   MENUITEM "E&xit"      ID_FILE_EXIT
  END
 POPUP "&Help"
  BEGIN
   MENUITEM "&Help"      ID_HELP
   MENUITEM SEPARATOR
   MENUITEM "&About"     ID_ABOUT
  END
END
$BCX_RESOURCE

CONST ID_MAINMENU = 102
ENUM
  ID_FILE_EXIT = 40001
  ID_FILE_OPEN
  ID_FILE_SAVEAS
  ID_FILE_NEW
  ID_HELP
  ID_ABOUT
  ID_TOOLBAR
END ENUM

GUI "BCXResourceDemo", PIXELS

GLOBAL Form1 AS hwnd
GLOBAL hTool AS hwnd

SUB FORMLOAD
  Form1 = BCX_FORM("$BCX_RESOURCE Demo", 0, 0, 480, 320, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN)
  SetMenu(Form1, LoadMenu(BCX_HINSTANCE, MAKEINTRESOURCE(ID_MAINMENU)))
  CENTER(Form1)
  SHOW(Form1)
  SHOW(hTool)
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_COMMAND
   IF CBCTL = ID_FILE_EXIT THEN PostMessage(hWnd, WM_CLOSE, 0, 0)
   IF CBCTL = ID_FILE_OPEN THEN GETFILENAME$("", "|*.*")
   IF CBCTL = ID_FILE_NEW THEN MSGBOX "$BCX_RESOURCE Demo" + CR$ + "Coded by Ad Rienks", "New", MB_ICONINFORMATION
   IF CBCTL = ID_FILE_SAVEAS THEN GETFILENAME$("", "|*.*", 1)
   IF CBCTL = ID_HELP THEN MSGBOX "More help is not (yet) available", "Help?", MB_ICONINFORMATION
   IF CBCTL = ID_ABOUT THEN MSGBOX "$BCX_RESOURCE Demo" + CR$ + "Coded by Ad Rienks", "About", MB_ICONINFORMATION
  END SELECT
END EVENTS

Build.bat compilation batch file:

CALL povars64.bat
bc test64

GETRESOURCE function

Purpose:

The GETRESOURCE function returns, if successful, a pointer to the first byte of the resource; otherwise NULL is returned. The size of the resource is also returned through the &ResourceSize parameter.

Syntax:

RetLPVOID = GETRESOURCE(ResourceID AS INTEGER, _
                       ResourceType AS STRING, _
                      &ResourceSize)

Return Value:

  • Data type: PTR
    RetLPVOID , if successful, is a pointer to the first byte of the resource; otherwise NULL is returned.

Parameters:

  • Data type: INTEGER
    ResourceID literal or variable integer identifier of the resource name.
  • Data type: STRING
    ResourceType literal or variable string identifier of the resource type.
  • Data type: &ULONG
    &ResourceSize is filled, by GETRESOURCE, with a unsigned long value specifying the resource size.

Example:

Save the example code below as test64.bas.
Save, as Build.bat, the batch file following the test64.bas code into the same directory as test64.bas.
Run Build.bat to compile.

$IPRINT_OFF

$RESOURCE "$PELLES$\Bin\porc.exe"

$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"

$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:console _
             -OUT:$FILE$.exe _
                  $FILE$.obj _
                $FILE$__.res"

BCX_RESOURCE 12345 RCDATA "Ring05.wav"
BCX_RESOURCE 12346 RCDATA "Alarm05.wav"
BCX_RESOURCE 12347 RCDATA "tada.wav"
 
GLOBAL hInstance AS HINSTANCE

PlayRcSound(hInstance, 12345)
SLEEP(100)
PlayRcSound(hInstance, 12346)
SLEEP(100)
PlayRcSound(hInstance, 12347)
?
PAUSE
 
SUB PlayRcSound (hInst AS HINSTANCE, ResourceID%)
  DIM lpSndData AS LPVOID
  DIM RSize AS ULONG
  lpSndData = GETRESOURCE(ResourceID%, RT_RCDATA, &RSize)
  IF lpSndData <> 0 THEN
    IF ResourceID = 12345 THEN
      PRINT " Playing Ring05.wav. Resource size: ", RSize
    END IF
    IF ResourceID = 12346 THEN
      PRINT " Playing Alarm05.wav. Resource size: ", RSize
    END IF
    IF ResourceID = 12347 THEN
      PRINT " Playing tada.wav. Resource size: ", RSize
    END IF
    PlaySound((LPCTSTR) lpSndData, hInstance, SND_MEMORY+SND_SYNC)
    EXIT SUB
  END IF
END SUB

Build.bat compilation batch file:

ECHO OFF
IF NOT EXIST Ring05.wav (
COPY "C:\Windows\Media\Ring05.wav"
IF NOT EXIST Ring05.wav (
ECHO Ring05.wav did not copy.
GOTO why
)
) ELSE (
GOTO fini
)
ECHO OFF
IF NOT EXIST Alarm05.wav (
COPY "C:\Windows\Media\Alarm05.wav"
IF NOT EXIST Alarm05.wav (
ECHO Alarm05.wav did not copy.
GOTO why
)
) ELSE (
GOTO fini
)
ECHO OFF
IF NOT EXIST tada.wav (
COPY "C:\Windows\Media\tada.wav"
IF NOT EXIST tada.wav (
ECHO tada.wav did not copy.
GOTO why
)
) ELSE (
GOTO fini
)
:why
ECHO Yours is to wonder why.
:fini
ECHO Ring05.wav in place.
ECHO Alarm05.wav in place.
ECHO tada.wav in place.

CALL povars64.bat
bc 

$NO_XXX directives

The following BCX translator directives prevent the emission of specific compiler headers, libraries, and pre-processor statements. These directives are best placed near the top of the source code before any other code gets translated. If any of these new directives are not used, the BCX generated C/C++ output file will contain all the headers, libraries, and pre-processor directives for Pelles, LccWin32, MSVC, GCC, Clang, Embarcadero (Borland) and the recently added Virtual Key (VK) values.


$NOWIN directive

Purpose:

Creates program with no WIN32 header files.

By default, BCX includes several common WIN32 header files. You can disable this by adding the line $NOWIN to your BASIC program source code. This will save you from having to remove those Win32 *.h files if you want to use the C code with another non-windows C compiler -- such as the free Turbo C compiler from Borland.


$NO_BORLAND directive

Purpose:

$NO_BORLAND creates program with no Borland / Embarcadero compiler specific header files, defines, macros and pragmas.


$NO_GCC_CLANG directive

Purpose:

$NO_GCC_CLANG creates program with no GCC or Clang compiler specific header files and defines.


$NO_LCCWIN directive

Purpose:

$NO_LCCWIN creates program with no LCCWin32 compiler specific header files and defines.


$NO_LIBS directive

Purpose:

$NO_LIBS creates program with no BCX default included libraries. The $NO_LIBS directive is useful when specifying static libraries inside batch or make files.


$NO_MSVC directive

Purpose:

$NO_MSVC creates program with no Microsoft compiler specific header files and defines.


$NO_PELLES directive

Purpose:

$NO_PELLES creates program with no Pelles C compiler specific header files and defines.


$NO_VKKEYS directive

Purpose:

$NO_VKKEYS creates program with no BCX default vitual key definition table.

Example:

As a practical example, consider this:

$NOWIN
$NO_BORLAND
$NO_GCC_CLANG
$NO_LCCWIN
$NO_LIBS
$NO_MSVC
$NO_PELLES
$NO_VKKEYS
PRINT "Hello World"

When translated, BCX gives us a much shorter transpiled C code that still compiles.

//*************************************************
//      Made with BCX BASIC To C/C++ Translator
//            Version 8.1.9 (10/20/2024)
// *************************************************
//    Translated for compiling with a C Compiler
// *************************************************
// ISO C Standard Library headers
#include <ctype.h>      // Character classification
#include <math.h>       // Mathematical functions
#include <setjmp.h>     // Non-local jumps
#include <stdarg.h>     // Variable arguments
#include <stddef.h>     // Common definitions
#include <stdio.h>      // Input/output
#include <stdlib.h>     // General utilities
#include <string.h>     // String handling
#include <time.h>       // Date and time
#include <errno.h>      // Error numbers (also POSIX)

// C99 Standard headers
#include <stdbool.h>    // Boolean type
#include <inttypes.h>   // Integer types

// POSIX headers
#include <fcntl.h>      // File control options

// Windows-specific headers
#include <process.h>    // Process control functions
#include <io.h>         // Low-level I/O (Windows POSIX subset)
#include <conio.h>      // Console I/O (Windows-specific)

// *************************************************
//            System Defined Macros
// *************************************************

#define BCXSTRSIZE 2048

// *************************************************
//                  Main Program
// *************************************************

int main(int argc, char *argv[])
{
  printf("%s\n","Hello World");
  return EXIT_SUCCESS;   // End of main program
}