Open Forum > Round Table
SB & C
(1/1)
Support:
I have been playing around with the CINT C interpreter and thought I would give it a try within ScriptBasic.
--- Code: Text ---PRINT "Hello "x = EXECUTE("cint world.c",-1,p)
--- Code: Text ---#include <stdio.h>main() { printf("World"); }
Output:
C:\scriptbasic\test>hello
Hello World
C:\scriptbasic\test>
Q. Can you pass variables to your C program and get the results of the C program returned back to the ScriptBasic program in a string?
A.
If the number of variables you want to pass are many, build the C program dynamically in SB and write it to a file with the embedded SB variable values as C constants. (the SB constants could be an #include file as well) If you only need to pass a couple values, then add them to the EXECUTE(cint pgm arg) and extract them from the C program's command line argument when it runs.
To return results back to SB, you need to redirect the output to a file and open it in SB after the C program runs and GET the results. If your going to use redirection or piping, you need to include the CMD processor in your EXECUTE statement.
--- Code: ---x = EXECUTE("cmd /C \"cint your_pgm.c > results.out\"", -1, pval)
--- End code ---
Support:
It looks like embedding CINT into ScriptBasic may not be all that hard to do. Having a C interpreter to compliment ScriptBasic syntax should make SB more attractive as a prototyping and learning tool. The goal with ScriptBasic is to provide a BASIC scripting tool that gets the job done quickly with as little code as possible and runs on everything. ScriptBasic is extensible, embeddable and can adapt to most of your one off programming needs.
CINT Users Reference
CINT API
Navigation
[0] Message Index
Go to full version