Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:17:23+00:00 2026-06-09T16:17:23+00:00

After having some trouble setting up SDL, I found out that SDL defines a

  • 0

After having some trouble setting up SDL, I found out that SDL defines a macro that replaces main:

#define main SDL_main

// And then
extern C_LINKAGE int SDL_main(int argc, char *argv[]);

This can also create compilation errors, if the main function doesn’t have the argc and argv parameters defined.

This macro gives me headaches just when I see it… Why does SDL need to redefine main? After some more searching, I found that some people #undef main, and use it the normal way.

So this is the question: why does SDL need to redefine main, what does it do? Are there any side effects to undefining it?

One thing I noticed is that SDL redirects standard output and error to files (and I don’t want this behavior), and this behavior stops if I undefine main.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:17:24+00:00Added an answer on June 9, 2026 at 4:17 pm

    Per the SDL Windows FAQ:

    You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code.

    If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.

    SDL requires initialization, so it injects its own main function that runs its initialization before calling your "main" function, which it renames to SDL_main so that it does not conflict with the actual main function. As noted in the FAQ, your main function must be of the form

    int main(int argc, char* argv[])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some trouble figuring out why my ImageView buttons stop working after I change
After having some trouble with setting up a thread to start my MIDI sequencer
I'm having some trouble figuring this out. I have a script that checks a
I'm having the weird problem that after having javascript inject some dom-elements the css-rules
I am having some trouble setting up my environment in Eclipse for ImageMagick via
I'm having some trouble setting the ExecutionTimeout element in my applications web.config. My page
I'm having some trouble using sessions with php.. I think I have figured out
After having some trouble with object deletion, I ran a simple test: Created a
I'm having some trouble setting up capybara (0.4.1.2) in a rails 2.3.8 app with
Having trouble setting up a website for my wedding. Hope someone can find out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.