Thread: Beginner Question: The main reason a pointer is used to create GUI window

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    26

    Beginner Question: The main reason a pointer is used to create GUI window

    I'm checking SDL and I see in the initial steps that a pointer of type SDL_WINDOW is made and then when passed to some other functions a window is initialized. I wonder how I should have guessed myself that I had to create a pointer and not a non-pointer variable?
    My own guess is that because otherwise unnecessary copying would be needed, whereas using a pointer, the function can return the very address of the only copy. Also my second guess is that a malloc is used inside the function which creates the window, and since malloc works only with pointers then the variable passed to that function must be a pointer too. (Thank you in advance)

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,578
    You're thinking of this the wrong way. The main reason SDL2's SDL_CreateWindow returns a pointer is because you can actually create multiple windows.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    26
    (Excuse me I reply late) So without pointer it will be impossible(I didn't get it)?

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,578
    Quote Originally Posted by narniat View Post
    So without pointer it will be impossible?
    Yes it will be. SDL2 uses the window pointer for almost all the functions that change the window in some way.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-08-2010, 11:13 PM
  2. Create a Main file
    By tironci in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 12:14 PM
  3. Connecting Dialog window to main window
    By vopo in forum Windows Programming
    Replies: 1
    Last Post: 11-26-2007, 07:55 PM
  4. Replies: 12
    Last Post: 03-27-2006, 07:03 AM
  5. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM

Tags for this Thread