Could someone explain this?

Started by
16 comments, last by jHaskell 10 years ago

And this:

int main()

Are you trolling now? Because, i can't tell if you are or if this is a question.
It's a real question. I've seen those things before within the main() and didn't know what they did.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

Advertisement

int main() just means that you don't care about command line arguments.

You can either use:

int main() -- and get no arguments,

or

int main(int argc, char * argv[]) -- and get an array of command line arguments as C-strings, where argc is the array size, and argv is the array of pointers.

And this:


int main()

Are you trolling now? Because, i can't tell if you are or if this is a question.

This is the guy who thinks he is going to create a more realistic GTA V replicate. The same guy who had half a page of quotes for a signature. The same guy who has been learning C++ for the last 4 months and doesn't know what a command line argument is. The same guy who has been part of the community for for 5 months, posted almost 500 posts and has a reputation of -367.

That Guy.

I apologize to the original poster whos topic has been hi-jacked.

int main() just means that you don't care about command line arguments.
You can either use:
int main() -- and get no arguments.

Thanks.
@kirkaff: and your point is?

My point is self-explainatory, need I say more? Your attention to detail is appalling my username is Kirkkaf13 (two k's one f), that is what is called a bug, I am sure you are familiar with them.

The original question has been answered, I think this thread should be closed before Nathan2222 posts and receives more down votes. Again, I would like to apologize for my actions but this is infuriating.

For the people reading this thinking I am being unreasonable or some sort of jerk, please read through Nathan2222 previous posts and thread hi-jacks.

Everyone back on topic, please. I won't ask nicely again.


I just thought the name would have more important in a main function and it used a lot.

They're important, yes. Names are vital to communicate intent to other programmers. Hence, dyou certainly shouldn't take Hodgman's suggestion of Sally too seriously!

But funnily enough C++ does not require that the names match between declarations and definitions.

void example(int one, int two);
 
int main()
{
    example(42, 13);
}
 
void example(int a, int b)
{
    std::cout << "A: " << a << ", B:" << b << std::endl;
}

In fact, you don't need to provide names when declaring a function, and if you don't wish to use a parameter you don't need to give it a name in a definition:

void example(int, int);
 
int main()
{
    example(42, 13);
}
 
void example(int a, int)
{
    std::cout << "A: " << a << ", but we don\'t care about B..." << std::endl;
}

It is typical for them to be present and to match, again to help provide clarity.

Thus, to the code that "calls" main, i.e. the runtime, it doesn't matter what the parameters names are or if they even have names.

Related to function/parameter naming, main has to be called main. You can't rename that.

(Well, for console stuff, at least. Win32 has different naming requirements, etc.)

Hello to all my stalkers.

For posterity, it's probably worth also pointing out that since the start of an array is kinda the same as a pointer, this is also valid:

int main (int argc, char** argv)

*edited out*

Somehow I missed reading over half the posts in this thread. No new information here.

This topic is closed to new replies.

Advertisement