Does this code follow C standards (e.g. C89, C99, C10x)?
void
main(int a,int b, int c, int d,char *msg){
if(d==1){
printf("%s\n",msg);
}else{
main(1,2,3,1,&"Hello Stackoverflow");
}
}
If not, why?
There's one error: &"Hello Stackoverflow" does not have type char*, so you shouldn't pass that to a function expecting that type.
Apart from that, this program is allowed by the Standard as an implementation-specific extension, but a compiler has the freedom to decline it.
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
(2011 Standard, latest draft section 5.1.2.2.1, emphasis added.)
There is no ban on recursive calls to main in the C Standard. This is a difference with C++, which does outlaw that.
You mean beside it won't run? main is defined to take int, char** as arguments.
Depending on the compiler, this either will fail to start up as the run-time can't find main(int, char**), or on older compilers it'll just crash because it piddles on the stack.
It's only valid under C99 and later if the implementation explicitly documents that main may take 5 parameters (4 int and 1 char *) and return void (that's the "or in some other implementation-defined manner" clause that larsmans referenced in his now-un-deleted answer, and I don't think that clause was present in C89).
Otherwise the behavior is undefined, meaning the compiler may or may not choke on it.
Related
What really are the valid signatures for main function in C? I know:
int main(int argc, char *argv[])
Are there other valid ones?
The C11 standard explicitly mentions these two:
int main(void);
int main(int argc, char* argv[]);
although it does mention the phrase "or equivalent" with the following footnote:
Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on.
In addition, it also provides for more (implementation-defined) possibilities.
The relevant text (section 5.1.2.2.1, but this particular aspect is unchanged from C99) states:
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
If they are declared, the parameters to the main function shall obey the following constraints:
The value of argc shall be nonnegative.
argv[argc] shall be a null pointer.
If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.
If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.
The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.
Note that this is for a hosted environment, the ones you normally see in C programs. A free-standing environment (such as an embedded system) is far less constrained, as stated in 5.1.2.1 of that same standard:
In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.
Standard C
For a hosted environment (that's the normal one), the C99 standard says:
5.1.2.2.1 Program startup
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;9) or in some other implementation-defined manner.
9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char **argv, and so on.
The C11 and C18 standards say essentially the same as the C99 standard.
Standard C++
The C++98 standard says:
3.6.1 Main function [basic.start.main]
1 A program shall contain a global function called main, which is the designated start of the program. [...]
2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall
have a return type of type int, but otherwise its type is implementation defined.
All implementations
shall allow both of the following definitions of main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
The C++ standard explicitly says "It [the main function] shall have a return type of type int, but otherwise its type is implementation defined", and requires the same two signatures as the C standard. So a 'void main()' is directly not allowed by the C++ standard, though there's nothing it can do to stop a non-standard conforming implementation from allowing alternatives (nor a standard conforming implementation from allowing alternatives as extensions to the standard).
The C++03, C++11, C++14, and C++17 standards say essentially the same as C++98.
Common Extension
Classically, Unix systems support a third variant:
int main(int argc, char **argv, char **envp) { ... }
The third argument is a null-terminated list of pointers to strings, each of which is an environment variable which has a name, an equals sign, and a value (possibly empty). If you do not use this, you can still get at the environment via 'extern char **environ;'. This variable is (still) not declared in any POSIX header (previous versions of this answer notwithstanding).
This is recognized by the C standard as a common extension, documented in Annex J:
###J.5.1 Environment arguments
¶1 In a hosted environment, the main function receives a third argument, char *envp[],
that points to a null-terminated array of pointers to char, each of which points to a string
that provides information about the environment for this execution of the program (5.1.2.2.1).
Microsoft C
The Microsoft VS 2010 compiler is interesting. The web site says:
The declaration syntax for main is
int main();
or, optionally,
int main(int argc, char *argv[], char *envp[]);
Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system by using a return statement. To return an exit code when main or wmain is declared as void, you must use the exit function.
It is not clear to me what happens (what exit code is returned to the parent or o/s) when a program with void main() does exit — and the MS web site is silent too.
Interestingly, MS does not prescribe the two-argument version of main() that the C and C++ standards require. It only prescribes a three-argument form where the third argument is char **envp, a pointer to a list of environment variables.
The Microsoft page also lists some other alternatives — wmain() which takes wide-character strings, and some more.
The Microsoft VS 2005 version of this page does not list void main() as an alternative. The versions from Microsoft VS 2008 onwards do.
Is int main() the same as int main(void)?
For a detailed analysis, see the end of my answer to What should main() return in C and C++. (It seems that I once considered that this question referred to C++, even though it doesn't and never did. In C++, there is no difference between int main() and int main(void) and int main() is idiomatic C++.)
In C, there is a difference between the two notations, but you only notice it in esoteric cases. Specifically, there's a difference if you call the main() function from your own code, which you're allowed to do in C and are not allowed to do in C++.
The int main() notation does not provide a prototype for main(), but that only matters if you call it recursively. With int main(), you might later (in the same function, or in another function) write int rc = main("absolute", "twaddle", 2): and formally the compiler shouldn't complain to the extent of refusing to compile the code, though it might legitimately complain (warn you) about it (and using -Werror with GCC would convert the warning into an error). If you use int main(void), the subsequent call to main() should generate an error — you said the function takes no arguments but tried to provide three. Of course, you can't legitimately call main() before you've declared or defined it (unless you are still using C90 semantics) — and the implementation does not declare a prototype for main(). NB: The C11 standard illustrates both int main() and int main(void) in different examples — both are valid in C, even though there's the subtle difference between them.
POSIX supports execve(), which in turn supports
int main(int argc, char *argv[], char *envp[])
The added argument is the environment, i.e. an array of strings of the form NAME=VALUE.
http://en.wikipedia.org/wiki/Main_function_(programming)#C_and_C.2B.2B
Besides the usual int main(int argc, char *argv[]) and the POSIX int main(int argc, char **argv, char **envp), on Mac OS X also supports
int main(int argc, char* argv[], char* envp[], char* apple[]);
Of course it's Mac-only.
On Windows there's
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]);
as the Unicode (actually, wide-character) variant. Of course there is WinMain too.
int main(void)
Under some OS (for example, Windows) also such is valid:
int main(int argc, char **argv, char **envp)
where envp gives an environment, otherwise accessible through getenv()
The standard says:
5.1.2.2.1 Program startup
The function called at program startup is named main. The
implementation declares no prototype for this function. It shall be
defined with a return type of int and with no parameters: int
main(void) { /* ... */ } or with two parameters (referred to here as
argc and argv, though any names may be used, as they are local to the
function in which they are declared): int main(int argc, char argv[])
{ / ... */ } or equivalent; 10) or in some other
implementation-defined manner.
If I write this:
#include <stdio.h>
struct some_struct
{
int i;
};
float main(struct some_struct s)
{
printf("Why does this main get called?\n");
}
Actually, it gets called with any prototype, as I see, and there is no any runtime error.
Why isn't it forbidden? Are there no reasons for that? Also, how does it get called if the signature is wrong?
I've used gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Starting with standard conformance:
1 In this International Standard, ‘‘shall’’ is to be interpreted as a requirement on an implementation or on a program; conversely, ‘‘shall not’’ is to be interpreted as a prohibition.
2 If a ‘‘shall’’ or ‘‘shall not’’ requirement that appears outside of a constraint or run time constraint is violated, the behavior is undefined. [...]
Look at the emphasis on the paragraph you quoted:
[...]. It shall be defined with a return type of int and with [...]
In the case,
float main(struct some_struct s){...}
"shall" requirement is outside of constraint because standard clearly states that main return type shall be int either with no parameters
int main(void) { /* ... */ }
or with two parameters
int main(int argc, char argv[]) { / ... */ }
This means that behavior of your program is undefined.
Your quote from the standard states that "some other implementation-defined manner". It appears that gcc is quite liberal in what it allows as signatures for main; it seems to ignore the parameter that you're passing. If you compile with gcc -Wall, you get warnings about main's prototype not being what it expects.
clang is less permissive about main's prototype. It will accept the return type of float with a warning, but will error out on the struct argument.
C looks up functions by name only, so the linker doesn't care about the unusual return type and parameters.
In C, if a function signature doesn’t specify any argument, it means that the function can be called with any number of parameters or without any parameters.
Hey checkout out this link - https://www.geeksforgeeks.org/difference-int-main-int-mainvoid/
This is my program:
main()
{
printf("hello world\n");
}
I get this warning when compiling it:
function should return a value
When changing main() to void main(), the warning disappears.
Why is that so?
There are few things which you should take note of :
The int is the main() function's return type. That means that the kind of value main() can
return is an integer.
main( ) was tolerated by the C90 compilers but not by C99 compilers which means its not a part of C99 standard anymore , so don't do this.
void main() is not a standard form ,some compilers allow this, but none of the standards have ever listed it as an option. Therefore,
compilers don't have to accept this form, and several don't. Again, stick to the standard form,
and you won't run into problems if you move a program from one compiler to another.
And one last thing , instead of writing main like this :
int main() // here you are being silent about passing arguments to main , meaning it may or may not take arguments
write like this :
int main(void)// this specifies there are no arguments taken by main
You might wanna look at the C99 standard for further details.
Quick summary: If you don't want to use command-line arguments, you should write:
int main(void) {
/* body of main function */
}
If you do:
int main(int argc, char *argv[]) {
/* ... */
}
These are the only portable ways to define the main function.
You should probably have a return 0; at the end, though it's not strictly necessary. Returning 0 indicates successful execution. There are ways to indicate that execution failed; I won't get into that here.
There's some history behind this. The rules for a valid definition of the main function have changed a bit across different releases of the C standard.
Before the introduction of the first official standard for C in 1989, the most common form was:
main()
{
/* ... */
}
Or, if you wanted to use command-line arguments:
main(argc, argv)
/* argc is implicitly of type int */
char *argv[];
{
/* ... */
}
There was no way to define a function that didn't return a value. If you didn't specify a return type, it defaulted to int.
The 1989 ANSI C standard (which was republished with editorial changes as the 1990 ISO C standard) introduced prototypes, function declarations and definitions that specify the parameter types. There are two equally valid definitions for main. You can use one or the other depending on whether you need to use command line arguments:
int main(void) {
/* ... */
}
or
int main(int argc, char *argv[]) {
/* ... */
}
(char *argv[] can also be written as char **argv. This rule applies only to parameter definitions.)
A given compiler may or may not choose to permit other forms. For example, some compilers support a third parameter envp.
Somehow, some authors have gotten the idea that void main() or void main(void) is valid. It can be valid for some particular compiler, but only if that compiler explicitly supports it. It's not portable. The odd thing about this is that the same standard that first introduced the void keyword simultaneously established the rule that main's return type is int.
void main() is useful as an indicator that the author of the book you're reading doesn't know the C language very well, and that you should find another book.
The story is different for "freestanding" (embedded) systems. For such systems, the program's entry point is entirely implementation-defined, and might not even be called main. Defining it as void main(void) may well be valid for such systems.
The 1999 ISO C standard dropped the "implicit int" rule. Taking advantage of that rule was probably never a good idea in the first place. As of ISO C 1990, you could legally use:
main(void) { /* ... */ }
because it was equivalent to:
int main(void) { /* ... */ }
As of the 1999 standard, the int is mandatory.
The 1999 standard also added a special-case rule: reaching the closing } of the main function is equivalent to executing return 0;. It's still not a bad idea to add the explicit return 0;, especially if your code might be compiled with a pre-C99 compiler.
The 2011 ISO C standard didn't make any changes in this area.
The difference between int main() and int main(void) is that the latter explicitly says that main takes no arguments; the former doesn't specify how many arguments it takes. Use the int main(void) form. There have been debates about whether int main() is even legal.
You can likely get away with writing void main(), since it's an error that compilers are not actually required to diagnose (it's undefined behavior unless the implementation documents it).
The bottom line: The proper definition of main has a long and varied history, and there are a lot of variant forms you can probably get away with using. But unless you're programming for an embedded system, there is no point in using anything other than one of the two officially valid forms:
int main(void) { /* ... */ }
int main(int argc, char *argv[]) { /* ... */ }
c automatically implies the datatype int to functions with no declared datatype. So as far as the compiler is concerned the above is:
int main()
{
printf("hello world\n");
}
This expects that you would return an integer at the end of it with a return statement. If you explicitly specify it as void main() you are telling the compiler that the function does not have a return value, hence no warning.
The reason that this is not an error is that if not specified, main() will return 0; at the end of execution. However the compiler is still giving you a warning that this is happening.
Best practice is to use int main() and then return 0 at the end of your program execution like this.
int main()
{
printf("hello world\n");
return 0;
}
See: this question for more information.
You got the warning because you didn't specify the return type of main.
You should always use int main, and return an int number, usually 0 for success.
int main()
{
printf("hello world\n");
return 0; //you can omit this since C99
}
Using void main on a hosted environment(normally we are, if not, the following doesn't have to be true) leads to undefined behavior, even though it works in some compilers, never use it.
The standard says main has two kinds of prototype, both returns int:
C11 5.1.2.2.1 Program startup
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;10) or in some other implementation-defined manner.
write
return 0 ;
at the last line.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What should main() return in C/C++?
Difference between void main and int main?
I have always been using the main method in C like
void main(){ // my code }
and it works pretty well for me.
I also know about the other int return type:
int main(void)
int main()
int main(int argc, char *argv[])
But I have not been able to find any resource that says that I can use void as a return type. Every book suggests that the return type must be int or else it be omitted. Then why does void main() work?
Is this dependent on the version of C that I am using? Or does it work because I use a C++ IDE? Please reply specific to C and not C++.
Only book authors seem to be privy to the place where a return type of void for main() is allowed. The C++ standard forbids it completely.
The C standard says that the standard forms are:
int main(void) { ... }
and
int main(int argc, char **argv) { ... }
allowing alternative but equivalent forms of declaration for the argument types (and the names are completely discretionary, of course, since they're local variables to the function).
The C standard does make small provision for 'in some other implementation defined manner'. The ISO/IEC 9899:2011 standard says:
5.1.2.2.3 Program termination
If the return type of the main function is a type compatible with int, a return from the
initial call to the main function is equivalent to calling the exit function with the value
returned by the main function as its argument;11) reaching the } that terminates the
main function returns a value of 0. If the return type is not compatible with int, the
termination status returned to the host environment is unspecified.
11) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main
will have ended in the former case, even where they would not have in the latter.
This clearly allows for non-int returns, but makes it clear that it is not specified. So, void might be allowed as the return type of main() by some implementation, but you can only find that from the documentation.
(Although I'm quoting C2011 standard, essentially the same words were in C99, and I believe C89 though my text for that is at the office and I'm not.)
Incidentally, Appendix J of the standard mentions:
J.5 Common extensions
The following extensions are widely used in many systems, but are not portable to all
implementations. The inclusion of any extension that may cause a strictly conforming
program to become invalid renders an implementation nonconforming. Examples of such
extensions are new keywords, extra library functions declared in standard headers, or
predefined macros with names that do not begin with an underscore.
J.5.1 Environment arguments
In a hosted environment, the main function receives a third argument, char *envp[],
that points to a null-terminated array of pointers to char, each of which points to a string
that provides information about the environment for this execution of the program
(5.1.2.2.1).
Why does void main() work?
The question observes that void main() works. It 'works' because the compiler does its best to generate code for programs. Compilers such as GCC will warn about non-standard forms for main(), but will process them. The linker isn't too worried about the return type; it simply needs a symbol main (or possibly _main, depending on the system) and when it finds it, links it into the executable. The start-up code assumes that main has been defined in the standard manner. If main() returns to the startup code, it collects the returned value as if the function returned an int, but that value is likely to be garbage. So, it sort of seems to work as long as you don't look for the exit status of your program.
From the horse's mouth:
5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;9)
or in some other implementation-defined manner.
9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
char ** argv, and so on.
The loophole is the "some other implementation-defined manner". An implementation may allow main to return void (or any other type), but it must explicitly document that such a signature is allowed. Otherwise the behavior is undefined, meaning the compiler can do anything it wants. The program may execute without any problems. It may execute, but leave the environment in a bad state. It may crash on exit. It may fail to load at all.
It is dependent on the compiler you are using, but void main is not compilable everywhere. I have seen compilers that won't compile a program with void main. I can not recall the particular case(for c), but I know for sure this happens in g++(yes I know this is c++).
The standard calls for main() to return int, but a lot of C compilers allow you to specify the return type of main() as void.
I recommend you get into the habit of returning int. Adding a
return 0;
to the end of your main() isn't too much effort.
I was acceptable in C89 but it is no longer considered "safe". Under C99, it is no longer acceptable.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284376&answer=1044841143
What really are the valid signatures for main function in C? I know:
int main(int argc, char *argv[])
Are there other valid ones?
The C11 standard explicitly mentions these two:
int main(void);
int main(int argc, char* argv[]);
although it does mention the phrase "or equivalent" with the following footnote:
Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on.
In addition, it also provides for more (implementation-defined) possibilities.
The relevant text (section 5.1.2.2.1, but this particular aspect is unchanged from C99) states:
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
If they are declared, the parameters to the main function shall obey the following constraints:
The value of argc shall be nonnegative.
argv[argc] shall be a null pointer.
If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.
If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.
The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.
Note that this is for a hosted environment, the ones you normally see in C programs. A free-standing environment (such as an embedded system) is far less constrained, as stated in 5.1.2.1 of that same standard:
In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.
Standard C
For a hosted environment (that's the normal one), the C99 standard says:
5.1.2.2.1 Program startup
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;9) or in some other implementation-defined manner.
9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char **argv, and so on.
The C11 and C18 standards say essentially the same as the C99 standard.
Standard C++
The C++98 standard says:
3.6.1 Main function [basic.start.main]
1 A program shall contain a global function called main, which is the designated start of the program. [...]
2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall
have a return type of type int, but otherwise its type is implementation defined.
All implementations
shall allow both of the following definitions of main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
The C++ standard explicitly says "It [the main function] shall have a return type of type int, but otherwise its type is implementation defined", and requires the same two signatures as the C standard. So a 'void main()' is directly not allowed by the C++ standard, though there's nothing it can do to stop a non-standard conforming implementation from allowing alternatives (nor a standard conforming implementation from allowing alternatives as extensions to the standard).
The C++03, C++11, C++14, and C++17 standards say essentially the same as C++98.
Common Extension
Classically, Unix systems support a third variant:
int main(int argc, char **argv, char **envp) { ... }
The third argument is a null-terminated list of pointers to strings, each of which is an environment variable which has a name, an equals sign, and a value (possibly empty). If you do not use this, you can still get at the environment via 'extern char **environ;'. This variable is (still) not declared in any POSIX header (previous versions of this answer notwithstanding).
This is recognized by the C standard as a common extension, documented in Annex J:
###J.5.1 Environment arguments
¶1 In a hosted environment, the main function receives a third argument, char *envp[],
that points to a null-terminated array of pointers to char, each of which points to a string
that provides information about the environment for this execution of the program (5.1.2.2.1).
Microsoft C
The Microsoft VS 2010 compiler is interesting. The web site says:
The declaration syntax for main is
int main();
or, optionally,
int main(int argc, char *argv[], char *envp[]);
Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system by using a return statement. To return an exit code when main or wmain is declared as void, you must use the exit function.
It is not clear to me what happens (what exit code is returned to the parent or o/s) when a program with void main() does exit — and the MS web site is silent too.
Interestingly, MS does not prescribe the two-argument version of main() that the C and C++ standards require. It only prescribes a three-argument form where the third argument is char **envp, a pointer to a list of environment variables.
The Microsoft page also lists some other alternatives — wmain() which takes wide-character strings, and some more.
The Microsoft VS 2005 version of this page does not list void main() as an alternative. The versions from Microsoft VS 2008 onwards do.
Is int main() the same as int main(void)?
For a detailed analysis, see the end of my answer to What should main() return in C and C++. (It seems that I once considered that this question referred to C++, even though it doesn't and never did. In C++, there is no difference between int main() and int main(void) and int main() is idiomatic C++.)
In C, there is a difference between the two notations, but you only notice it in esoteric cases. Specifically, there's a difference if you call the main() function from your own code, which you're allowed to do in C and are not allowed to do in C++.
The int main() notation does not provide a prototype for main(), but that only matters if you call it recursively. With int main(), you might later (in the same function, or in another function) write int rc = main("absolute", "twaddle", 2): and formally the compiler shouldn't complain to the extent of refusing to compile the code, though it might legitimately complain (warn you) about it (and using -Werror with GCC would convert the warning into an error). If you use int main(void), the subsequent call to main() should generate an error — you said the function takes no arguments but tried to provide three. Of course, you can't legitimately call main() before you've declared or defined it (unless you are still using C90 semantics) — and the implementation does not declare a prototype for main(). NB: The C11 standard illustrates both int main() and int main(void) in different examples — both are valid in C, even though there's the subtle difference between them.
POSIX supports execve(), which in turn supports
int main(int argc, char *argv[], char *envp[])
The added argument is the environment, i.e. an array of strings of the form NAME=VALUE.
http://en.wikipedia.org/wiki/Main_function_(programming)#C_and_C.2B.2B
Besides the usual int main(int argc, char *argv[]) and the POSIX int main(int argc, char **argv, char **envp), on Mac OS X also supports
int main(int argc, char* argv[], char* envp[], char* apple[]);
Of course it's Mac-only.
On Windows there's
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]);
as the Unicode (actually, wide-character) variant. Of course there is WinMain too.
int main(void)
Under some OS (for example, Windows) also such is valid:
int main(int argc, char **argv, char **envp)
where envp gives an environment, otherwise accessible through getenv()