What’s the difference between Display XOpenDisplay(0) and XOpenDisplay(NULL)?
#include <X11/Xlib.h> struct MwmHints { unsigned long flags; unsigned long functions; unsigned long decorations; long input_mode; unsigned long status; }; enum { MWM_HINTS_FUNCTIONS = (1L << 0), MWM_HINTS_DECORATIONS = (1L << 1), MWM_FUNC_ALL = (1L << 0), MWM_FUNC_RESIZE = (1L << 1), MWM_FUNC_MOVE = (1L << 2), MWM_FUNC_MINIMIZE = (1L << 3), MWM_FUNC_MAXIMIZE = (1L << 4), MWM_FUNC_CLOSE = (1L << 5) }; extern "C" { void borderless(Window window) { Display *display = XOpenDisplay(0); Atom mwmHintsProperty = XInternAtom(display,"_MOTIF_WM_HINTS",0); struct MwmHints hints; hints.flags = MWM_HINTS_DECORATIONS; hints.decorations = 0; XChangeProperty(display,window,mwmHintsProperty,mwmHintsProperty,32, PropModeReplace,(unsigned char *)&hints,5); XCloseDisplay(display); } }
In the above code I wrote an *.SO library for Linux that when called removes the window decorations of the specified window. In the line of that code which reads:
Display *display = XOpenDisplay(0);
I have tried replacing that with:
Display *display = XOpenDisplay(NULL);
And both usages seem to successfully remove the window decorations on the Ubuntu 16.04 LTS laptop I am testing it on.
I’ve read somewhere (I can’t remember where) that depending on how you use XOpenDisplay, it will react differently if there are multiple monitors hooked up to your computer. I don’t have multiple monitors to test with, so I need to know if using 0 is any different from using NULL, which leads to my next question, which I’ll post as a separate question.
Thanks.
Advertisement
Answer
There’s no difference whatsoever
NULL
is defined as 0 (possibly casted to void *
in C, but not in C++). The two calls are actually identical.