Link to home
Create AccountLog in
Avatar of cs02rm0
cs02rm0

asked on

Xlib, XFetchName compile error

Error:
olib.cpp: In function `void query(int)':
olib.cpp:70: error: cannot convert `char* (*)[256]' to `char**' for argument `3
   ' to `int XFetchName(Display*, long unsigned int, char**)'

This is the offending code method:

void query(int w)
{
        Display *d = XOpenDisplay(0);
        Window null, *wlist;
        unsigned int n;
        XQueryTree(d, DefaultRootWindow(d), &null, &null, &wlist, &n);
        XFlush(d);
        for (int i = 0; i<n; i++)
        {
                if(viewable(wlist[i]) == 1)
                {
                        char *windowname[256];
                        XFetchName(d, wlist[i], &windowname); // This is the particular line causing the error.
                        cout << windowname << "\n";
                        if (windowname) XFree(windowname);
                }
        }
}

I guess the crux of my problem is that I don't know what the difference between a char * (*) and a char ** is?

Thanks in advance for any suggestions.
Avatar of NovaDenizen
NovaDenizen

I think you just need to change the line to:
                      XFetchName(d, wlist[i], windowname);

The ampersand is unnecessary.  char *windowname[256], an array of char *'s,  looks like 'char **'.  &windowname doesn't make much sense, since it is basically like taking the address of a literal constant.  Since windowname is an array, it is its own pointer to itself.

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
You're right, jkr.  I didn't check the API, I just wanted to get rid of the syntax error.
>>I didn't check the API, I just wanted to get rid of the syntax error

That would work 'syntax-wise', but IMHO then 'XFree(windowname);' would lead to an error. It's the ole "who allocates it, frees it" rule that can lead to so much confusion is complex systems with a lot of DLLs and other libraries involved...
Avatar of cs02rm0

ASKER

Thanks. Spot on :)