Talk:Main function

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Merge Request[edit]

I propose that this article be merged with Entry point as that article is about the entry point of the program. The description "Main function" only really applies to C on this list as Java and C# have a "Main method" and Haskell a "Main IO Action". The entry point article may be expanded as right now it is only stub quality, but right now I don't think this article should be separate from it. -- (talk) 14:54, 29 October 2013 (UTC)

Languages that don't use main[edit]

Why on earth are Ruby and other languages that don't use "main" listed on this page? All their descriptions say is "this language doesn't use main". That's like writing a page about wheels, and having huge sections of the page devoted to fish because "fish don't have wheels". It makes no sense.

If Ruby were somehow unique in it's non-use of main, it might make sense to include it here. But it's not. There are literally hundreds of other languages that don't use main that aren't listed here. How about Rexx, for instance?

This smacks of favoritism. There is no other logical reason to include these languages on this page--and certainly not a whole section to themselves! If it were a single sentences like "Some languages, such as Ruby, do not use a main section." that might be acceptable. But devoting a whole section to a language that has NOTHING to do with the topic of the page is blatant promotionism.

Computer languages not relevant to the use of "main" should be removed from this page. Alternatively if this is not possible for some reason, a less-biased and more inclusive listing of languages that do not use main should be supplied instead. —Preceding unsigned comment added by (talk) 04:32, 2 July 2008 (UTC)

I'm going to have to agree with you on this one. Very odd to have those on this page. I propose these languages lacking Main be removed from the page as well. Barring any valid suggestion contrary to this I'll do it here in the next few days when I have a few minutes.BcRIPster (talk) 05:26, 8 July 2008 (UTC)
The above doesn't appear to have been done so I've done it. It's ridiculous that there were more examples of languges which *don't* have a main() than those that do! Also It think the REALbasic example should go as it's more about general execution entry points rather than main() specifically but I left it in as I was on the fence. Everything else I've removed is clearly just promotionism as stated above and against the point of the article. As also already stated, that's start listing all the types of fish that exist on the "wheels" page for the fact they all don't have wheels. I think a note needs adding to the source for future edits to be mindful of whether the examples they add actually do relate to main() or not. (talk) 14:17, 24 September 2013 (UTC)

args, argc, argv[edit]

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:/w will not do a listing of directory C:\W - it will treat /w as a switch, with the end result the same as for dir /w c: (try it!). Similarly, your example with hello.exe/foo/bar baz would be treated as hello.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)
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 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)

"It is guaranteed that argc is non-negative and that argv[argc] is not a null pointer" AFAIK is wrong. argv[argc] is guaranteed to be NULL in ANSI C. Historically, it used to be -1 up to Unix V6. —Preceding unsigned comment added by (talk) 18:40, 12 October 2010 (UTC)

apple vector[edit]

According tho this article: There is a 4th argument passed to main in both the Mac OSX and darwin OS. —Preceding unsigned comment added by (talk) 10:24, 4 March 2008 (UTC)

Nice. Added. EdC (talk) 13:17, 8 March 2008 (UTC)

Isn't it 'where execution begins' but also[edit]

'ultimately ends'? --Leladax (talk) 19:11, 27 July 2008 (UTC)

Not if you program concurrently. (talk) 19:41, 25 April 2013 (UTC)

Reference is just text?[edit]

How is reference 1 valid? It doesn't cite any source and tries to validate itself because "that's the way it is" apparently. (talk) 19:53, 31 August 2009 (UTC)

Needs more details[edit]

It would be helpful to add more details of how the main method is used in various programming languages, including some of the more important commands that are called within "main." --AFriedman (talk) 20:32, 10 December 2009 (UTC)

C/C++ Main Function[edit]

int main() means the same thing as int main(void) and is valid in both c/c++. I realize the standards documents for c and c++ are inconsistent in how they show this particular case.  snaphat  01:18, 10 August 2011 (UTC)

For C++, Section 8.3.5 Functions of the Working Draft, Standard for Programming Language C++ states "The parameter list (void) is equivalent to the empty parameter list."  snaphat  01:30, 10 August 2011 (UTC)

For C, Section Function declarators of (including prototypes) of the ISO/IEC 9899:TC3 (Final Draft of C99 including revisions) states "The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters."  snaphat  01:32, 10 August 2011 (UTC)

int main() means the same thing as int main(void) in C++, but not in C, as you've quoted. --Cubbi (talk) 05:15, 10 August 2011 (UTC)
That is correct if you are referring to non-prototype declarations in C. However, we are only talking about prototype declarations and definitions. Specifically, I will use an example (which is assuming C):
//Non-prototype declaration.
void foo();

//prototype declaration.
void bar(void);

//Prototype declaration and definition.
void foo(void) {}

//prototype declaration and definition.
void bar() {}

Since the article is specifically referring to function prototypes, the cases we are talking about are the 2nd through 4th declarations. The 1st isn't a prototype declaration; ergo, what I stated is true.  snaphat  17:18, 10 August 2011 (UTC)

Oh, I should have stated that this section is in regard to an edit that added both int main() and int main(void) prototype variants for main and confused the issue by specifying one as from c++ and the other as c based on specific examples found in the corresponding standards documents.  snaphat  21:15, 10 August 2011 (UTC)

How are function prototypes even relevant given that "The implementation declares no prototype for this function." (9899:1999 Anyway, I do agree that mixing up C and C++ in the same chapter of this page is terribly confusing, if that's what you're getting at. --Cubbi (talk) 04:22, 11 August 2011 (UTC)
The point of that statement is simply to say the user is responsible for declaring function mains prototype- not the implementation. It is worded as such so that implementations themselves do not attempt to declare a function prototype for main. It is not saying that main doesn't have a prototype. By definition main has one of the two prototypes written in 9899:1999.  snaphat  12:45, 11 August 2011 (UTC)
Suppose, I should have said that it can have any number of prototypes, those are just the ones defined by the standard.  snaphat  13:45, 11 August 2011 (UTC)