refactor: replace object-like #define constants with constexpr - #351
refactor: replace object-like #define constants with constexpr#351zzcgumn wants to merge 3 commits into
Conversation
Convert object-like constant macros in library/src and library/tests to typed constexpr definitions, matching the existing style in utility/constants.h. ALL_CAPS names are kept (renaming the legacy public API identifiers would be a break). - api/dll.h: DDS_VERSION, MAXNOOF*, 28 RETURN_* -> constexpr int; 28 TEXT_* -> inline constexpr const char* const - api/dds.h: THREADMEM_*, MAXNODE/MINNODE, SIMILAR* -> constexpr int - ab_stats.hpp DDS_MAXDEPTH, scheduler.hpp HASH_MAX, timer_group.cpp TIMER_DEPTH, dealer_par.cpp BIGNUM, trans_table_s.cpp N/W SIZE/INIT + LSIZE -> constexpr int - system.cpp DDS_SYSTEM_THREAD_* -> constexpr int ([[maybe_unused]]: most are behind platform #ifdefs) - utility/debug.h: DDS_*_PREFIX / DDS_DEBUG_SUFFIX -> inline constexpr const char* const; drop the now-redundant #ifndef fallbacks in scheduler.cpp in favour of #include <utility/debug.h> - tests: calc_par_test.cpp R2..RA, args.cpp DTEST_NUM_OPTIONS Left as macros: DEBUG and DDS_TEST_MEMORY_SANITIZER (used in #if), function-like macros, include guards, and platform/export flags. Values are unchanged; full bazel build (incl. wasm/web/jni/python) and all 93 tests pass, including the scheduler/ab_stats/debug_all define-gated builds. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGCVvZx1GL4TxgHkVDU6bG
- dll.h: keep DDS_VERSION / MAXNOOFBOARDS / MAXNOOFTABLES as #define. This is the frozen legacy C API header and external consumers conventionally test the version/limits in the preprocessor (#if DDS_VERSION >= ...). - dll.h + debug.h: drop `inline` from the string constants. At namespace scope `constexpr const char* const` has internal linkage, matching both the macros they replace and the sibling `int` constants; `inline` would have promoted them to external-linkage inline variables on a public header pulled into every binding TU. - system.cpp: scope [[maybe_unused]] to the platform-gated DDS_SYSTEM_THREAD_* subset; _BASIC and _SIZE are used unconditionally. - cpp.instructions.md: mirror the "legacy public-API constants keep ALL_CAPS as constexpr" carve-out already added to copilot-instructions. - DdsStatus.java, copilot-instructions.md: RETURN_* are now constexpr constants, not macros; fix stale wording / examples. - timer_group.cpp: comment the relocated TIMER_DEPTH constant. Full bazel build (incl. wasm/web/jni/python) and all 93 tests pass, including the scheduler/ab_stats/debug_all define-gated builds and jni/tests:export_set_test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGCVvZx1GL4TxgHkVDU6bG
There was a problem hiding this comment.
Pull request overview
This PR refactors object-like #define constants into constexpr constants across the DDS library and tests, aligning the broader codebase with the existing library/src/utility/constants.h style and improving type-safety, scoping, and debuggability.
Changes:
- Converted various numeric constants from macros to
constexpr intin core library and tests. - Converted several debug-related string constants from macros to
constexprstring constants and updated scheduler includes accordingly. - Updated specs and style-guide documentation to clarify the intended constants/macro conventions (including the legacy
ALL_CAPSexception).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| specs/constants-and-debug.md | Updates spec wording to reflect debug flags/macros and constexpr debug prefixes. |
| library/tests/calc_par_test.cpp | Replaces rank bitmask #defines with constexpr int test constants. |
| library/tests/args.cpp | Replaces DTEST_NUM_OPTIONS macro with constexpr int. |
| library/src/utility/debug.h | Replaces debug filename prefix/suffix macros with constexpr string constants. |
| library/src/trans_table/trans_table_s.cpp | Replaces TT sizing macros (NSIZE, WSIZE, etc.) with constexpr int. |
| library/src/system/timer_group.cpp | Replaces TIMER_DEPTH macro with constexpr int and adds clarifying comment. |
| library/src/system/system.cpp | Replaces thread-backend index macros with constexpr int (with [[maybe_unused]] where appropriate). |
| library/src/system/scheduler.hpp | Replaces HASH_MAX macro with constexpr int. |
| library/src/system/scheduler.cpp | Removes macro fallback block and includes <utility/debug.h> under DDS_SCHEDULER. |
| library/src/dealer_par.cpp | Replaces BIGNUM macro with constexpr int. |
| library/src/api/dll.h | Keeps version/limits as macros; converts RETURN_/TEXT_ constants to constexpr declarations. |
| library/src/api/dds.h | Replaces several configuration macros with constexpr int. |
| library/src/ab_stats.hpp | Replaces DDS_MAXDEPTH macro with constexpr int. |
| jni/java/org/dds/ffm/DdsStatus.java | Updates comments to refer to RETURN_* “constants” rather than “macros”. |
| .github/instructions/cpp.instructions.md | Documents legacy ALL_CAPS constant exception after macro→constexpr conversions. |
| .github/copilot-instructions.md | Mirrors the same naming guidance update for constants vs macros. |
Suppressed comments (1)
library/src/api/dll.h:38
- The PR description says DDS_VERSION/MAXNOOFBOARDS/MAXNOOFTABLES were converted to constexpr, but this file explicitly keeps them as preprocessor macros. Please update the PR description (or, if the intention is truly to convert them, remove this comment and convert these defines) so the change summary matches the actual behavior.
/* Version 3.1.0. Allowing for 2 digit minor versions */
// These three stay object-like macros: this is the frozen legacy C API
// header and external consumers conventionally test the version / limits in
// the preprocessor (e.g. #if DDS_VERSION >= 30100, #ifdef MAXNOOFBOARDS).
#define DDS_VERSION 30100
#define MAXNOOFBOARDS 200
#define MAXNOOFTABLES 40
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- dll.h: make the TEXT_* constants array-typed (constexpr const char TEXT_x[] = "...") instead of const char* const, per Copilot review. This restores the string-literal macro semantics the reviewer flagged (sizeof(TEXT_x) gives the length, array-of-char type) while still decaying to const char* for strcpy / EXPECT_STREQ. Kept non-inline so linkage stays internal/per-TU, matching both the replaced macros and the sibling RETURN_* int constants. Full bazel build (incl. wasm/web/jni/python) and all 93 tests pass. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGCVvZx1GL4TxgHkVDU6bG
|
@tameware , do you still have Copilot credits left for this month? |
|
I do! Will request a review in the morning.
…On Fri, Aug 28, 2026 at 12:02 AM Martin Nygren ***@***.***> wrote:
*zzcgumn* left a comment (dds-bridge/dds#351)
<#351 (comment)>
@tameware <https://github.com/tameware> , do you still have Copilot
credits left for this month?
—
Reply to this email directly, view it on GitHub
<#351?email_source=notifications&email_token=ABC4PYDGENYI6GEPJHT7UG35MCVYPA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNBUGU3TIMRRG43KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5445742176>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABC4PYCRUZELTBJ4BK3JLSD5MCVYPAVCNFSNUABEKJSXA33TNF2G64TZHMZDMOJYHAZDANR3JFZXG5LFHM2TENZQHA2TANZTGKQXMAQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
library/src/api/dll.h:36
- The PR description’s “Changes” table says
DDS_VERSION,MAXNOOFBOARDS, andMAXNOOFTABLESwere converted toconstexpr, but this header intentionally keeps them as#definemacros. It also describesTEXT_*asinline constexpr const char* const, but the implementation is nowconstexpr const char TEXT_*[](array-typed, non-inline). Please update the PR description (and/or the “Intentionally left as macros” section) to match the actual changes so reviewers/users aren’t misled.
// header and external consumers conventionally test the version / limits in
// the preprocessor (e.g. #if DDS_VERSION >= 30100, #ifdef MAXNOOFBOARDS).
#define DDS_VERSION 30100
#define MAXNOOFBOARDS 200
|
The changes are certainly an improvement. I find the description confusing. It uses
|
Context
Numeric and string constants across the library were defined as object-like
preprocessor macros (
#define MAXNOOFBOARDS 200). Macros carry no type, ignorescope, and don't show up in the debugger.
library/src/utility/constants.halready established the target style (
constexpr int DDS_STRAINS = 5;); thischange extends it to the remaining object-like constant macros in
library/srcand
library/tests.ALL_CAPSnames are kept — renaming the legacy public C API identifiers(
DDS_VERSION,RETURN_NO_FAULT, ...) would be a real API break. The ABI isunaffected (a
constexpr intof the same value emits no symbol), and theapi/dll.hheader already cannot compile as C (C++ trailing-return syntax, andit includes the already-
constexprconstants.h).Changes
library/src/api/dll.hDDS_VERSION,MAXNOOFBOARDS,MAXNOOFTABLES, 28RETURN_*→constexpr int; 28TEXT_*→inline constexpr const char* const(TEXT_SUIT_OR_RANK\-continuation collapsed)library/src/api/dds.hTHREADMEM_*,MAXNODE,MINNODE,SIMILARDEALLIMIT,SIMILARMAXWINNODESlibrary/src/ab_stats.hppDDS_MAXDEPTHlibrary/src/system/scheduler.hppHASH_MAXlibrary/src/system/system.cppDDS_SYSTEM_THREAD_*(10) —[[maybe_unused]], since most sit behind platform#ifdefslibrary/src/system/timer_group.cppTIMER_DEPTHlibrary/src/trans_table/trans_table_s.cppNSIZE,WSIZE,NINIT,WINIT,LSIZElibrary/src/dealer_par.cppBIGNUMlibrary/src/utility/debug.hDDS_*_PREFIX/DDS_DEBUG_SUFFIXstringslibrary/src/system/scheduler.cpp#ifndef DDS_SCHEDULER_PREFIXfallback block; replaced with#include <utility/debug.h>library/tests/calc_par_test.cppR2..RArank bitmaskslibrary/tests/args.cppDTEST_NUM_OPTIONS.github/copilot-instructions.md,specs/constants-and-debug.mdIntentionally left as macros
DEBUG(play_analyser.cpp) andDDS_TEST_MEMORY_SANITIZER(test) — both usedin
#if; function-like macros (HAND_ID,AB_COUNT, timer macros…); includeguards; and platform/export flags (
DLLEXPORT,WINVER, debug feature flags…).examples/hands.cppis out of scope.Verification
All values are unchanged, so no test edits were needed.
bazelisk build //...— full build incl. wasm/web/JNI/python ✅bazelisk test //...— 93/93 pass ✅bazelisk build --define=scheduler=true / --define=ab_stats=true / --define=debug_all=true //library/src:dds✅bazelisk test --define=ab_stats=true //library/tests/ab_search:ab_stats_test //library/tests/ab_search:tt_lookup_test✅🤖 Generated with Claude Code
Closes #350