You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C programmers (and even bash programmers) are used to do tricks with command line arguments. A very common trick is testing argv[0] (this is C!) in order to assume certain defaults. For example, grep, egrep and fgrep are all the same executable really, which behaves differently depending on how it is invoked.
The entry point of a C application is:
intmain(intargc, void*argv[])
So, when you invoke fgrep abc file.txt, this is what the application sees:
Now compare with Scala Native. The entry point of a Scala application is:
defmain(args: Array[String]):Unit
If you invoke `fgrep-out abc file.txt``, this is what the application sees:
args(0) ="abc"
args(1) ="file.txt"
Discussion
I suggest that Scala Native somehow passes the name of the executable to the program.
Possibly the runtime enviroment could simply expose a variable which contains the argv[0] which was ignored when args was populated. Something like exposing...
privatevarargv0=""defprogram:String= argv0
... and initializing argv0 like this:
argv0 = argv(0)
just before:
82while (c < argc-1) {
83// use the default Charset (UTF_8 atm)84 args(c) = fromCString(argv(c+1))
85 c +=186 }
Ideas? Thanks
The text was updated successfully, but these errors were encountered:
I vote for a dual entry point. The programmer choose which one in build.sbt:
JVM style, the default:
def main(args: Array[String]): Unit
C style, if some configuration is set in build.sbt
def main(argc: Int, argv: Ptr[CString]): Int
As a side effect, this solution supports better the case where the application uses the Scala syntax but calls only C functions as it doesn't introduce unused dependencies on java.lang.String and scala.Array
Context
C programmers (and even bash programmers) are used to do tricks with command line arguments. A very common trick is testing
argv[0]
(this is C!) in order to assume certain defaults. For example,grep
,egrep
andfgrep
are all the same executable really, which behaves differently depending on how it is invoked.The entry point of a C application is:
So, when you invoke
fgrep abc file.txt
, this is what the application sees:Now compare with Scala Native. The entry point of a Scala application is:
If you invoke `fgrep-out abc file.txt``, this is what the application sees:
Discussion
I suggest that Scala Native somehow passes the name of the executable to the program.
Possibly the runtime enviroment could simply expose a variable which contains the
argv[0]
which was ignored whenargs
was populated. Something like exposing...... and initializing
argv0
like this:just before:
Ideas? Thanks
The text was updated successfully, but these errors were encountered: