👉 Please note that the $NOMAIN directive, to code your own main() function, is deprecated. All variations of SUB MAIN and FUNCTION MAIN are automatically detected, making $NOMAIN unnecessary but still allowed.
The $NOMAIN directive creates a program without a main() function.
BCX usually creates the C main() function. $NOMAIN is useful for creating a library of compiled code modules that do not contain a main function. $NOMAIN also can be used if you want to code your own main() function.
Place the $NOMAIN directive near the top of the source code file.
Copy the code below and save as ExternProcs.bas
$NOMAIN FUNCTION Sum (a, b) AS INTEGER FUNCTION = a + b END FUNCTION FUNCTION Mult (a, b) AS INTEGER FUNCTION = a * b END FUNCTION
Copy the code below and save as CallExternProcs.bas
$HEADER extern int Sum(int a, int b); extern int Mult(int a, int b); $HEADER PRINT "40 + 10 = " & Sum(40, 10) PRINT "50 * 10 = " & Mult(50, 10)
Copy the code below and save as Build.bat
CALL povars64.bat bc CallExternProcs.bas bc ExternProcs.bas pocc /Tamd64-coff /W2 /Ze /Zx CallExternProcs.c pocc /Tamd64-coff /W2 /Ze /Zx ExternProcs.c polink /release /MACHINE:X64 /SUBSYSTEM:CONSOLE CallExternProcs.obj ExternProcs.obj /out:"CallExternProcs.exe"
40 + 10 = 50 50 * 10 = 500
Here is a simple example to code your own main() function which also demonstrates a method of forcing a variable to be declared in the main() procedure.
$NOMAIN SUB MAIN () DIM RAW i i = 10 PRINT i END SUB
Both SUB MAIN () and FUNCTION MAIN () are translated to C code
int main(void)
Therefore, command line arguments cannot be retrieved because the int argc, char *argv[] parameters of the C 'main' function are not declared.