To prove a point to the non-believers lets write a program and run it under DOS and UNIX.
main (int argc, char* argv)
{
_int i;
_for(i=0; i
_{
__printf("Argument is %s\n", argv[i]);
_}
}
Lets run this program with the parameter 'Hello World'.Under both DOS and UNIX two statements each will be displayed: the program name and 'Hello World'.
Now doesn't this prove that C under DOS and UNIX is the same?
No !!!
Lets run the program again, but with different parameter. Instead of 'Hello World', pass a * .
And what we get then?
Under DOS we get the program name and the star ' * '.
But under UNIX there is a difference. Instead of the star we get a directory listing.
There is the proof that C under these two OS's is different? Not so fast.
Lets first see what happened.Under DOS, C took the star as an argument and printed it. That's because the DOS shell, COMMAND.COM, took it for what it was: a star. The UNIX shell, however, is intelligent. It sometimes proceeds to deduce. In this case it interpreted the star to mean a directory listing. This directory listing was then passed to the program as an argument which proceeded to display the files on screen.
On the face of it, yes, the program worked differently and therefore we can say C is different under DOS and UNIX. But is it really the program that give us this difference in output? Not at all. It was the shell. If the shell had not been built to interpret the star, the directory listing would never have appeared. And that is hardly the fault of the program.
0 comments:
Post a Comment