Thread: Pointers to structures & functions arguments

  1. #1
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193

    Pointers to structures & functions arguments

    I'm calling my function like this
    Code:
    GdkColor *color; // structure
    showColor(&color);
    And my function is written like this
    Code:
    void showColor(GdkColor *color) {
    	GdkWindow *rootwin;
     	GdkImage *image;
    	GdkColormap *cmap;
    	gint x, y;
    	guint32 pixel;
    	GdkDisplay *display = NULL;
    	GdkScreen *screen = NULL; 
    	display = gdk_display_get_default ();
    	screen = gdk_display_get_default_screen (display); 
    	gdk_display_get_pointer (display, NULL, &x, &y, NULL);
    	rootwin = gdk_screen_get_root_window(gdk_screen_get_default());
    	cmap = gdk_screen_get_system_colormap(gdk_screen_get_default());
    
    	image = gdk_drawable_get_image(rootwin, x, y, 1, 1);
    	pixel = gdk_image_get_pixel(image, 0, 0);
    	g_object_unref(image);
    
    	gdk_colormap_query_color(cmap, pixel, &color);
    	color->red = color->red / 65535.0;
    	color->green = color->green / 65535.0;
    	color->blue = color->blue / 65535.0;
    }
    I'm getting errors on the color pointer to the structure..

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    color is a pointer, showColor takes a pointer, showColor(color); is sufficient (no &)

  3. #3
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I'm also getting errors when calling the color elements..

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I'm sure we've mentioned before, but "Post your actual error messages!!!"
    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.

  5. #5
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Sorry, I've mistaken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions Taking Dif. Numbers of Arguments at Dif. Times?
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2009, 04:12 PM
  2. Generic Pointers to structures
    By dunxton in forum C Programming
    Replies: 8
    Last Post: 02-20-2009, 10:23 AM
  3. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Pointers, arrays , functions
    By sballew in forum C Programming
    Replies: 19
    Last Post: 09-16-2001, 11:12 PM