tags:

views:

60

answers:

1

Hi. I was following this tutorial, bit stuck here:

This code doesn't compile, and the error message is

c:35: error: invalid initializer

I'm not sure what's wrong with the line

XGCValues valu=CapButt|JoinBevel;

infact, I copied it from the said tutorial. Here's the full code I have:

#include <stdio.h>
#include <X11/Xlib.h>
#include <unistd.h>

int main()
{
     Display *display=XOpenDisplay(NULL);
     int scr=DefaultScreen(display);
     Window root_window=RootWindow(display,scr);
     unsigned int width=DisplayWidth(display,scr)/3;
     unsigned int height=DisplayHeight(display,scr)/3;
     unsigned int border=2;

     Window      my_win=XCreateSimpleWindow(display,root_window,0,0,width,height,border,BlackPixel(display,scr),WhitePixel(display,scr));
     GC gc;
     XGCValues valu=CapButt|JoinBevel;
     unsigned long valmask=GCCapStyle|GCJoinStyle;
     gc=XCreateGC(display,my_win,valmask,&valu);
     XDrawLine(display,my_win,gc,5,5,20,20);

     XMapWindow(display,my_win);
     XFlush(display);
     sleep(10);
     return 0;
 }

Thank You

A: 

The example in the tutorial is wrong - if you look in <X11/Xlib.h> or read the XCreateGC man page you'll see XGCValues is a struct, not a integral type, so you would need to initialize it with something like:

XGCValues values;

values.cap_style = CapButt;
values.join_style = JoinBevel;
alanc