SDL and main()

Jun 8, 2009 at 10:46pm
I found this in SDL.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifdef __cplusplus
#define C_LINKAGE	"C"
#else
#define C_LINKAGE
#endif /* __cplusplus */

/* The application's main() function must be called with C linkage,
   and should be declared like this:
#ifdef __cplusplus
extern "C"
#endif
	int main(int argc, char *argv[])
	{
	}
 */
#define main	SDL_main

/* The prototype for the application's main() function */
extern C_LINKAGE int SDL_main(int argc, char *argv[]);

Now, I've been using _tmain() from VC++ for months without problems, mostly because that #define gave me a linker error with main(), I'm guessing because I was avoiding SDLmain.lib (which I assume defines SDL_main()).
Do you think there'd be any problems if I use the regular main()?
Jun 9, 2009 at 12:07am
That just seems wrong, redefining the word main! SDL documentation should tell you to call your main SDL_main and leave out the define. I'd just use SDL_main, making it obvious what's going on.
Jun 9, 2009 at 12:13am
I forgot to mention that now I'm #undefing main.
Jun 9, 2009 at 12:19am
And still avoiding SDLmain.lib, I assume (there must be a main lurking in there). The only thing I'd worry about is what does the main in SDLmain.lib do (some kind of initialization) and is it necessary for what you need.
Jun 9, 2009 at 1:02am
I have no idea what it does, but the program has been working correctly without it for several months in several systems without it, so I don't think it's something all that useful. At the very least, it doesn't seem to do anything I need. Either that or my users are not reporting issues (wouldn't be something unheard of, really. People prefer to complain rather than report).

By the way, the reason I'm avoiding SDLmain.lib is because it requires me to dynamically link to the runtime, and when I do, I get several conflicts between the runtime and the libraries, which I'm admittedly too lazy to resolve.
Jun 9, 2009 at 1:36am
Today after writing several hundred lines of code I get a linker error about having no entry point and also about redefinition of main, always having something to do with this line
#define main SDL_main
That's a good idea about undefining main.
Jun 9, 2009 at 5:36am
This is a known issue with SDL.
When I tried it - I did do the undefine main thing.

Redefining the define also works IIRC
#define SDL_main main
Last edited on Jun 9, 2009 at 5:36am
Topic archived. No new replies allowed.