Talk:Main function (programming)
From Wikipedia, the free encyclopedia
[edit] args, argc, argv
Java uses the space character as a delimiter for separate elements in the args array. Are there any other characters that act as delimiters (such as "-" or "/")? What about other programming languages? --Abdull 18:29, 16 April 2007 (UTC)
- I don't think this is strictly defined anywhere in the standard - it's OS-specific. -- int19h 06:02, 18 April 2007 (UTC)
-
- Correct. The language defines the interface that the O/S should use to pass command line arguments to the program. It is the O/S that determines the format of those arguments on the command line. wrp103 (Bill Pringle) (Talk) 14:23, 18 April 2007 (UTC)
-
-
- On the other hand, IIRC DOS (and Windows) doesn't parse the command line into arguments and passes a single string to the executable, which then has to parse it itself. Might this differ between Windows-hosted environments? –EdC 05:53, 19 April 2007 (UTC)
-
-
-
-
- Yes, it might be that. In case of Windows, it provides the GetCommandLine API function which returns the entire command line as a single string, and it's up to the C library to parse it correctly. Nonetheless, I am not aware of any DOS/Windows C compilers which do not adhere to the standard DOS/Windows conventions in that regard (in particular, that '/' is also a separator). -- int19h 07:16, 19 April 2007 (UTC)
-
-
-
-
-
-
- I infer from your username that you know more about DOS than I do, but to avoid misleading readers of this page in the future... '/' (forward slash) is not an argument separator on any system I know. No modern Windows programs treat / as a separator in argument lists, because if they did, you wouldn't be able to specify paths in Unix style: "foo/bar/baz" must be treated as one argument, not three (or five?). However, DOS and Windows do assume that '/' won't appear in command names, so "hello.exe/foo/bar baz" will try to execute "hello.exe" with arguments "/foo/bar" and "baz", rather than executing "hello.exe/foo/bar" with the single argument "baz". --Quuxplusone 01:02, 19 May 2007 (UTC)
-
-
-
-
-
-
-
-
- DOS and Windows do assume that '/' is an argument separator. For example,
dir c:/wwill not do a listing of directory C:\W - it will treat/was a switch, with the end result the same as fordir /w c:(try it!). Similarly, your example withhello.exe/foo/bar bazwould be treated ashello.exe /foo /bar baz- this is commonly used in DOS to shorten commands by cramping the switches together with no whitespace, for example:dir /w/b/on C:\(wide listing, lowercase names, order by name). On the other hand,dir "c:/w"treats the entire quoted string as a Unix-style path. To sum it up: Unix style paths are allowed in DOS/Win world, but slash in command line is treated as an argument separator where possible (i.e., in any case except when it's a non-first character in a quoted string). At least that's how it works for built-in and standard commands, third-party ones can be different - I've seen quite a few which allow for switches to begin with slash, do not treat slash by itself as a separator. -- int19h 08:52, 19 May 2007 (UTC)
- DOS and Windows do assume that '/' is an argument separator. For example,
-
-
-
-
-
-
-
-
-
-
- As far as I know, that is specific to the built-in commands like dir, cd, copy, ren, del, etc. and doesn't apply to external .exe's 201.212.126.164 22:01, 5 September 2007 (UTC)
-
-
-
-
-
For the record, under unix the argument parsing is done by a shell, which means it is neither apart of the language nor the operating system. 23:25, 26 June 2007 (UTC)
[edit] apple vector
According tho this article: http://unixjunkie.blogspot.com/2006/02/char-apple-argument-vector.html There is a 4th argument passed to main in both the Mac OSX and darwin OS. —Preceding unsigned comment added by 76.169.2.116 (talk) 10:24, 4 March 2008 (UTC)

