Anonymous | Login | Signup for a new account | 2025-06-19 15:22 UTC | ![]() |
My View | View Issues | Change Log | Roadmap | All Projects Issue Support Ranking | Rules | My Account |
View Revisions: Issue #3905 | [ Back to Issue ] | ||
Summary | 0003905: zandronumbinaries.cpp OS-dependent macro hell is quite ugly (and broken) | ||
Revision | 2021-09-24 15:40 by WubTheCaptain | ||
Description | This macro hell was too cumbersome to read for me:Quote from src/plugins/zandronum/zandronumbinaries.cpp#ifdef Q_OS_WIN32 #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip" #define ZANDRONUM_BINARY_NAME "zandronum.exe" #define SCRIPT_FILE_EXTENSION ".bat" #else #ifndef __x86_64__ #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2" #else #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2" #endif #ifndef Q_OS_DARWIN #define ZANDRONUM_BINARY_NAME "zandronum" #else #define ZANDRONUM_BINARY_NAME "Zandronum.app" #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum" #endif #define SCRIPT_FILE_EXTENSION ".sh" #endif The first Q_OS_WIN32 seems fine. Then the latter confused me. I forgot it's not possible to re-define a macro without undefining it first in C++. This initially led me to believe 64-bit Windows would download GNU/Linux binaries and use a binary named zandronum, instead of zandronum.exe. After copying the code to my text editor and adding spaces, I figured the first Q_OS_WIN32 block doesn't even end in #endif and changed my understanding of the code entirely. With spaces and newlines, the above code is the same as: #ifdef Q_OS_WIN32 #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip" #define ZANDRONUM_BINARY_NAME "zandronum.exe" #define SCRIPT_FILE_EXTENSION ".bat" #else #ifndef __x86_64__ #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2" #else #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2" #endif #ifndef Q_OS_DARWIN #define ZANDRONUM_BINARY_NAME "zandronum" #else #define ZANDRONUM_BINARY_NAME "Zandronum.app" #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum" #endif #define SCRIPT_FILE_EXTENSION ".sh" #endif Suddenly more understandable (thanks, spaces!), yet still ugly (and broken in some ways). Other issues here, some which may be seperate issues:
|
||
Revision | 2021-09-24 18:06 by WubTheCaptain | ||
Description | This macro hell was too cumbersome to read for me:Quote from src/plugins/zandronum/zandronumbinaries.cpp#ifdef Q_OS_WIN32 #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip" #define ZANDRONUM_BINARY_NAME "zandronum.exe" #define SCRIPT_FILE_EXTENSION ".bat" #else #ifndef __x86_64__ #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2" #else #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2" #endif #ifndef Q_OS_DARWIN #define ZANDRONUM_BINARY_NAME "zandronum" #else #define ZANDRONUM_BINARY_NAME "Zandronum.app" #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum" #endif #define SCRIPT_FILE_EXTENSION ".sh" #endif The first Q_OS_WIN32 seems fine. Then the latter confused me. I forgot it's not possible to re-define a macro without undefining it first in C++. This initially led me to believe 64-bit Windows would download GNU/Linux binaries, and use a binary named zandronum instead of zandronum.exe. After copying the code to my text editor and adding spaces, I figured the first Q_OS_WIN32 block doesn't even end in #endif and changed my understanding of the code entirely. With spaces and newlines, the above code is the same as: #ifdef Q_OS_WIN32 #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip" #define ZANDRONUM_BINARY_NAME "zandronum.exe" #define SCRIPT_FILE_EXTENSION ".bat" #else #ifndef __x86_64__ #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2" #else #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2" #endif #ifndef Q_OS_DARWIN #define ZANDRONUM_BINARY_NAME "zandronum" #else #define ZANDRONUM_BINARY_NAME "Zandronum.app" #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum" #endif #define SCRIPT_FILE_EXTENSION ".sh" #endif Suddenly more understandable (thanks, spaces!), yet still ugly (and broken in some ways). Other issues here, some which may be seperate issues:
|
Copyright © 2000 - 2025 MantisBT Team |