SDL main?

Started by
20 comments, last by dustydoodoo 19 years ago
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.
Advertisement
LOL! i have seen main() but ive never seen "int argc, char *argv[]" in the main functions arguments.
Sure i will write my signature, just gimme a piece of paper
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.
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]
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.
Sure i will write my signature, just gimme a piece of paper
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!
so a simple SDL program for just creating a coloured window probably doesnt use it?
Sure i will write my signature, just gimme a piece of paper
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]
THANKS!! man it feels nice to finnaly understand stuff!
Sure i will write my signature, just gimme a piece of paper
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
Bring more Pain

This topic is closed to new replies.

Advertisement