Thread: functions that return pointers (SDL2)

  1. #1
    Registered User
    Join Date
    Jun 2020
    Posts
    1

    functions that return pointers (SDL2)

    In SDL2 there is a function

    SDL_Window*SDL_CreateWindow(constchar*title, int x,
    int y,
    int w,
    int h,
    Uint32 flags)

    the return value of this function is SDL_window* which is a pointer and there are some other functions (like SDL_DestroyWindow (SDL_Window* window)) which takes the SDL_Window pointer as an argument.
    How can we define these kind of pointers defined?
    Is it mean that we have a pointer that points a struct with slots x,y,w,h,flags?
    Do we need to define these kind of pointers like pointer to int or pointer to float?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,874
    Code:
    SDL_Window *win;
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    733
    The documentation for the Library and functions would have provided this information and more!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,111
    > Is it mean that we have a pointer that points a struct with slots x,y,w,h,flags?
    > Do we need to define these kind of pointers like pointer to int or pointer to float?
    Let's illustrate your question in terms of FILE* from stdio.h

    Code:
    FILE *fp = fopen("filename", "r");
    int ch = fgetc(fp);
    fclose(fp);
    A 'FILE' is what is called an opaque type - Opaque data type - Wikipedia
    You can't meaningfully do anything along the lines of fp->member to get at information about the open file. You must use the appropriate interface function, passing fp as one of the parameters.

    The same goes for a SDL_Window *win pointer. Your only task as a programmer is to keep that pointer safe, and pass it along to whatever other SDL_xxx functions you want to call that take a SDL_Window * pointer parameter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL2 Line Artifacting
    By Bluepixel in forum Linux Programming
    Replies: 5
    Last Post: 06-02-2020, 05:18 PM
  2. SDL2 - GCC vs. G++ segmentation fault
    By Zacariaz in forum C Programming
    Replies: 8
    Last Post: 06-01-2015, 06:23 AM
  3. SDL2 Codeblocks error
    By russiancircles in forum Game Programming
    Replies: 2
    Last Post: 05-08-2014, 06:08 AM
  4. question for functions that return pointers
    By alexsoad in forum C Programming
    Replies: 5
    Last Post: 07-03-2012, 09:57 AM
  5. Replies: 4
    Last Post: 03-11-2005, 05:45 PM

Tags for this Thread