They all do the same thing.
I want to know what is the difference between those functions, and why there isn't only one. :
Thank uCode:int main() int main(int argc, char *argv[]) int main(int argc, char *argv) int main(void) void main() void main(void)
They all do the same thing.
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
I don't think the main function in C could be of void return type.
1st and 4th are the same.
2nd's main function can take multiple parameters where as the 3rd's can only take one ( why would you do that? ).
Read about arrays and command line arguments to get detailed explanations. Once you understand them this won't be a problem anymore.
thank u guyz (:
The 'standard' declaration of main, should be..
[php]int main( int argc, char *argv[] )[/php]
I tend to use..
[php]int main( int argc, char **argv )[/php]
because of the whole 'array decay to pointer' thing. I don't know, I like pointers.
The return value of main should be an int, notifying the user/OS whether the program terminated correctly or not (You should return the constants EXIT_FAILURE or EXIT_SUCCESS, as defined in <stdlib.h>)
The first argument to main is the amount of arguments passed in via the command line, the second argument is a pointer to the array of arguments.
This provides you enough functionality to retrieve information about how the program should run, and notify the OS how the program terminated.
The reason you see a few different declarations, as far as I can tell, is because some compilers aren't as strict. Don't expect your code to be portable if you don't conform to the standard.
Last edited by -Raz0r-; 10-10-2010 at 11:59 PM.
Languages: C, C++, x86 ASM, PHP, Lua
I've always learnt that
void main();
Is wrong, wrong, wrong!
And should never be used, it's not defined in the ASNI standard, and thus it's not really part of the language. I think it's something that .net permits you to do. But a native compiler should not allow void main();
I'm SCHiM
Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.
Polymorphic engine
Interprocess callback class
SIN
Infinite-precision arithmetic
Hooking dynamic linkage
(sloppy)Kernel mode Disassembler!!!
Semi debugger
Hell_Demon (10-11-2010)
Ah we-a blaze the fyah, make it bun dem!
i also would prefer
int main(int argc, char **argv) instead of
int main(int argc, char *argv[])
because a array is nothing more than a pointer, and in my eyes **argv is better because if you're calling a function with this parameter **argv it is more clear that it should be a pointer to a pointer like:
char * c;
&c is a pointer to a pointer then
and with ** it is clear that you need a POINTER to a POINTER
But in the end there isn't any damn different so use what you want
_____________________________________________
READING TUTORIAL:
1. READ MY POST
2. THINK ABOUT MY POST
3. PRESS THANKS
4. MAYBE CORRECT MY POSTS :P
Dijkstra:
"Computer Science is no more about computers than astronomy is about
telescopes."
THANKS BUTTON RIGHT DOWN --->
But If you know your program won't be receiving any parameters through the command line?
Wouldn't one be eating space one doesn't need?
I mean, if we look at an assembly entry point (proc main) we don't see any special variables either...
Code:main: main proc push eax push ... mov... ca... c... ... main endp END main
I'm SCHiM
Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.
Polymorphic engine
Interprocess callback class
SIN
Infinite-precision arithmetic
Hooking dynamic linkage
(sloppy)Kernel mode Disassembler!!!
Semi debugger
I'm SCHiM
Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.
Polymorphic engine
Interprocess callback class
SIN
Infinite-precision arithmetic
Hooking dynamic linkage
(sloppy)Kernel mode Disassembler!!!
Semi debugger
One can only assume the calling convention is the standard cdecl (Caller maintains the stack)
AFAIK from my little experiments involving 'TinyPE' and 'TinyELF' files, 'main' isn't the real entry point - there's a proxy layer between the OS and your program's 'main' function and this is where the stack is maintained(?)
Languages: C, C++, x86 ASM, PHP, Lua
Thank you all for your answers