Wednesday, February 11, 2009

Using CINT - C/C++ Interpreter - Getting Started

One of things I favor scripting languages (Ruby, Python) over none scripting (JAVA, C/C++) is there is no need to follow time consuming cycle of write-compile-run. Even with the best IDE, I still feels the pain of typing command, hit key combination, waiting for computer doing. This is especially true when I need to explore some API, test some ideas. So when I discovered CINT, a C/C++ Interpreter, I gave it a try. With CINT, we can type C/C++ code directly in it's interactive CINT console and get the result. CINT is available for Windows and many UNIX platform(s) some LINUX clone has CINT pre-installed. We start CINT console by type e.g. (on Windows)
d:\cint-5.16.19\cint.exe
cint.exe>{#include <iostream>
cint.exe>{cout << "Hello World\n";}  
Hello World (class ostream)2085223112 
C/C++ code shall be type inside curly bracket {...}, CINT doesn't allow to define function in interactive console
> { int func999() {return 999;} }
Limitation: Function can not be defined in a command line or a tempfile
You need to write it in a source file (tmpfile)(1)
!!!Dictionary position rewound... !!!Error recovered!!!
So we have to create separate file e.g.
# func999.cpp
int func999() {
return 999;
}
,load it in the console and call a function inside
cint.exe>L func999.cpp
cint.exe>{func999();}
Some of the most frequently used commands includes
L  - load file in to the console
U  - unload the file
file - show which files are currently loaded
reset - reset memory of CINT console to initial state,unload all files
q - quit CINT console

No comments: