| 1 | /* |
| 2 | Print sizes of some C, EGL, X types. |
| 3 | To make sure our Pascal headers have same size for these types. |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include <EGL/egl.h> |
| 9 | |
| 10 | #include <X11/Xlib.h> |
| 11 | #include <X11/Xutil.h> |
| 12 | |
| 13 | void main() |
| 14 | { |
| 15 | /* Note: Use %zu to print size_t values. |
| 16 | See https://stackoverflow.com/questions/5943840/how-do-i-print-the-size-of-int-in-c#5943869 |
| 17 | */ |
| 18 | |
| 19 | // C types |
| 20 | printf("int size: %zu\n", sizeof(int)); |
| 21 | printf("unsigned int size: %zu\n", sizeof(unsigned int)); |
| 22 | printf("unsigned long size: %zu\n", sizeof(unsigned long)); |
| 23 | |
| 24 | // EGL types |
| 25 | printf("EGLint size: %zu\n", sizeof(EGLint)); |
| 26 | |
| 27 | // EGL types that are aliases to other libraries (X, WinAPI) types, |
| 28 | // we have to be ultra-careful with these to have same size in Pascal headers. |
| 29 | printf("EGLNativeDisplayType size: %zu\n", sizeof(EGLNativeDisplayType)); |
| 30 | printf("EGLNativePixmapType size: %zu\n", sizeof(EGLNativePixmapType)); |
| 31 | printf("EGLNativeWindowType size: %zu\n", sizeof(EGLNativeWindowType)); |
| 32 | |
| 33 | /* |
| 34 | X types. |
| 35 | These are pointer-sized, in practice (32 on 32-bit systems, 64 on 64-bit). |
| 36 | |
| 37 | Note: Ignore a confusing statement from X.h header, that says: |
| 38 | |
| 39 | """ |
| 40 | * _XSERVER64 must ONLY be defined when compiling X server sources on |
| 41 | * systems where unsigned long is not 32 bits, must NOT be used in |
| 42 | * client or library code. |
| 43 | """ |
| 44 | |
| 45 | and does |
| 46 | |
| 47 | """ |
| 48 | #ifndef _XSERVER64 |
| 49 | ... |
| 50 | typedef unsigned long XID; |
| 51 | #else |
| 52 | ... |
| 53 | typedef CARD32 XID; |
| 54 | """ |
| 55 | |
| 56 | So it seems that X developers wanted XID to be always 32-bit, |
| 57 | even on 64-bit systems... But actually _XSERVER64 is not defined, ever. |
| 58 | |
| 59 | As this program shows in fact, on x86_64 systems, |
| 60 | - "unsigned long" is 64-bit |
| 61 | - and X.h *does not* define _XSERVER64 |
| 62 | - and thus XID is also 64-bit |
| 63 | */ |
| 64 | printf("XID size: %zu\n", sizeof(XID)); |
| 65 | printf("Pixmap size: %zu\n", sizeof(Pixmap)); |
| 66 | printf("Window size: %zu\n", sizeof(Window)); |
| 67 | } |