RE:command line args

From: Masaharu Goto (MXJ02154@nifty.ne.jp)
Date: Wed Aug 26 1998 - 13:09:00 MEST


Sean,

>My question is regarding how does CINT deals with command line arguments ?

Yes, it does. Just the same way as the compiled C/C++ program hadles the
arguments.

>eg: this doesn't work
>
>.L cmd.C
>main(3,{"main","foo","blah"})
>
>#include <iostream.h>
>main(int argc, char* argv[]) {
> for(int i=0; i<argc;i++){
>    cout << argv[i] << endl;
> }
>}

This is a very interesting notation. It is not supported by cint and neither
by other C/C++ processing systems,  this inspires me. 
I guess your expectation is that , like  perl or shell script,  a script
interpreter should execute commands out side of function scope. This mechanism
is used by other script interpreters and it plays a role of main function.
Cint handles C/C++ code, so the entry point is main() function rather than
statements appears in global scope.

In this case, to do what you want, suppose you have cmd.C as follows

// cmd.C /////////////////////////
#include <iostream.h>
main(int argc, char* argv[]) {
 for(int i=0; i<argc;i++){
    cout << argv[i] << endl;
 }
}
// end of cmd.C //////////////////

Start cint or ROOT and use the command as follows.

root[0] .L cmd.C
root[1] char *argv[]={"main","abc","def"};
root[2] main(3,argv);

Or use raw cint interpreter from UNIX or DOS command line,

$  cint  cmd.C   abc  def

This will do.

Masaharu Goto



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:36 MET