“在没有演员的情况下使指针从整数形成” - 我如何满足GCC?

时间:2013-06-27 06:00:35

标签: c pointers casting x11

我正在用C编写我的第一个X11应用程序,并且在尝试检索应用程序窗口的大小时遇到​​了一个主要问题。

temp.c:30:2 warning: passing argument 3 of 'XGetGeometry' makes pointer from integer without a cast

我知道这只是一个警告,但它仍会导致段错误,这并不好玩。这是我的代码:

static void loop();
static void initialize();
static void cleanUp();
static void run();

/* Variables */

static int screenNumber;
unsigned long White;
unsigned long Black;
long eventMask;
static Display *currentDisplay;
static Window currentWindow;
static unsigned int windowWidth;
static unsigned int windowHeight;
static GC graphicsController;
static XEvent XEvents;

void loop() {
        XGetGeometry(currentDisplay, currentWindow, DefaultRootWindow(currentDisplay), NULL, NULL, &windowWidth, &windowHeight, NULL, NULL);

        XDrawLine(currentDisplay, currentWindow, graphicsController, 0, 0, (int)windowWidth, (int)windowHeight);
        XDrawLine(currentDisplay, currentWindow, graphicsController, 0, (int)windowHeight, (int)windowWidth, 0);
}

void initialize() {
        currentDisplay = XOpenDisplay(NULL);
        screenNumber = DefaultScreen(currentDisplay);

        White = WhitePixel(currentDisplay, screenNumber);
        Black = BlackPixel(currentDisplay, screenNumber);

        currentWindow = XCreateSimpleWindow(    currentDisplay,
                                                DefaultRootWindow(currentDisplay),
                                                0, 0,
                                                500, 500,
                                                0, Black,
                                                White);

        XMapWindow(currentDisplay, currentWindow);
        XStoreName(currentDisplay, currentWindow, "rGot - X11");

        eventMask = StructureNotifyMask;
        XSelectInput(currentDisplay, currentWindow, eventMask);

        do{
                XNextEvent(currentDisplay, &XEvents);
        }while(XEvents.type != MapNotify);

        graphicsController = XCreateGC(currentDisplay, currentWindow, 0, NULL);

        XSetForeground(currentDisplay, graphicsController, Black);
}

void run() {
        eventMask = ButtonPressMask|ButtonReleaseMask;
        XSelectInput(currentDisplay, currentWindow, eventMask);
        do{
                XNextEvent(currentDisplay, &XEvents);
                loop();
        }while(1==1);
}

void cleanUp() {
        XDestroyWindow(currentDisplay, currentWindow);
        XCloseDisplay(currentDisplay);
}

int main(){
        initialize();
        run();
        cleanUp();
        return 0;
}

我知道我的指针已经做错了,但是我对此很新...这是我的设置:

  • Ubuntu 12.04 LTS
  • 使用以下内容进行编译:{{1​​}}

对于那些稍后发现的人 - 我最初尝试使用gcc tempc -o temp -lX11是完全错误的!

要正确使用它,我必须执行以下操作:

XGetGeometry

这是基于我的调查结果here

1 个答案:

答案 0 :(得分:7)

根据这两个函数的文档,DefaultRootWindow()会返回Window,而XGetGeometry()则需要Window*来表示第三个参数。因此,正如警告所说,您正在传递一个普通类型,其中指向该类型的指针。