Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL main?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
21 replies to this topic

#1 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 05:24 PM

I was just wondering what the arguments in the SDL main mean?, i dont ussually like using stuff i dont understand, and the main looks like this int main(int argc, char *argv[]) I know its a small thing but i would just like to know :)

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 01 April 2005 - 05:29 PM

its just standart entry point for console program, you can find description of it in the MSDN, argc - number of input command line arguments, arv - arguments themselves

#3 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 05:38 PM

Whats an entry point? and a console program?

#4 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 05:46 PM

Oh wait, are "int argc, char *argv[]" arguments or parameters?

#5 X3   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 April 2005 - 05:52 PM

just check MSDN. i thought argument and parameter are synonyms. entry point is the part of the program from which it starts. console program .. well dunno how do describe it.. its just console program

#6 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 06:05 PM

Man will this ever stop!!? Whats a synonym!?, i looked it up on google, but i couldnt find anything! oh wait never mind, it a word with the same or near the same meaning of the another.

#7 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 06:35 PM

K, i got one more question, why does a SDL program need this in the main function? And why would these parameters be usefull? could someone tell me in simple words? lol, i dont have a very good vocabulary.

#8 X3   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 April 2005 - 06:45 PM

its not SDL. Every Windows program should have either WinMain or main functions which are entry points for executables.

#9 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 06:54 PM

whats an executable?

#10 X3   Members   -  Reputation: 115

Like
0Likes
Like

Posted 01 April 2005 - 06:58 PM

*.exe

#11 kaysik   Members   -  Reputation: 382

Like
0Likes
Like

Posted 01 April 2005 - 07:20 PM

Quote:
Original post by X3
its not SDL. Every Windows program should have either WinMain or main functions which are entry points for executables.


Actually it kind of is SDL. The way SDL works is with you declaring your own main() function which it then uses #defines to overwrite with its own so it can initialise your application correctly. Because of the fickleness of #define you have to use the correct declaration otherwise it won't work. You can't for instance have int main() or void main() you need the full declaration int main(int argc, char **argv)

As for dustydoodoo ... how long have you been programming? I suggest you go look up some c/c++ tutorials on google befor launching into SDL if you've never seen main() befor.

#12 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 April 2005 - 07:22 PM

LOL! i have seen main() but ive never seen "int argc, char *argv[]" in the main functions arguments.

#13 kaysik   Members   -  Reputation: 382

Like
0Likes
Like

Posted 01 April 2005 - 07:26 PM

Ok well for a console application (an app which has no gui - just uses text output) main accepts those arguments. its basically just a list of everything passed in on the command line.

So if you run your program like this:

myapp.exe -p something.txt

you'll have "myapp.exe" "-p" and "something.txt" as your command line arguments. argc says how many there are (in this case its 3), and argv is the char arrays of each string. This is the full and proper declaration of main - and IMHO should always be used.

As for the entry point: its the part of your program that starts running first - so when you run your program it'll start at the beginning of main.

#14 Rob Loach   Moderators   -  Reputation: 1500

Like
0Likes
Like

Posted 02 April 2005 - 03:42 AM

They are command line arguments used when you run the actual program, just like kaysik said. Here's a small demo I put together to test them:

#include <iostream>

int main ( int argc, char *argv[] )
{
// Check if there is only one program argument
if(argc == 2){ // 2 because 1 is the program name
// Display the output
std::cout << "Argument: " << argv[1] << std::endl;
std::cin.get();
} else {
// Display an error using the program name
std::cout<<"Usage: "<< argv[0] <<" <output>\n";
std::cin.get();
}
}


Rob Loach [Website] [Projects] [Contact]

#15 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 April 2005 - 12:33 PM

hey thanks for all the info, but the one thing i dont get is why would you need this? esspetially(dont know how to spell) when you dont use the command line? because this isnt in one of those dos windows.

#16 Drew_Benton   Crossbones+   -  Reputation: 1713

Like
0Likes
Like

Posted 02 April 2005 - 12:41 PM

Quote:
Original post by dustydoodoo
hey thanks for all the info, but the one thing i dont get is why would you need this? esspetially(dont know how to spell) when you dont use the command line? because this isnt in one of those dos windows.


You might not be using it, but trust me when I say lots of other people do. Part of a good game design is to use some sort of Data Driven design. What that means is rathet than hard code in all your runtime settings, such as the width, height, etc.. you just load it from a file. However, in itself, that would still require hard coding in a filename to load. To get around that, you could juse let the user call your program with a parameter that contains the file to load, which would make it nearly all data driven!

#17 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 April 2005 - 12:51 PM

so a simple SDL program for just creating a coloured window probably doesnt use it?

#18 Drew_Benton   Crossbones+   -  Reputation: 1713

Like
0Likes
Like

Posted 02 April 2005 - 12:54 PM

Quote:
Original post by dustydoodoo
so a simple SDL program for just creating a coloured window probably doesnt use it?


Not unless you make it [smile]

#19 dustydoodoo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 April 2005 - 12:55 PM

THANKS!! man it feels nice to finnaly understand stuff!

#20 owiley   Members   -  Reputation: 125

Like
0Likes
Like

Posted 02 April 2005 - 01:13 PM

it also alow u to drop flies in like for editors and compliers
it very powerful not just for dos programs it so important to programmers that
microsoft went ahead and add it to there main()(aka-WinMain(...))
in the WinMain(...) it should be the last field




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS