Skip to content

Conversation

johnjohnlin
Copy link

Dear author:
Thank you for creating and maintaining this project. Recently, I’ve been exploring preprocessor-based arithmetic, and I’d like to propose a pull request that significantly extends the supported range for for-like macros with much more concise code.

As noted in your map.h comment:

Because the preprocessor can't do arithmetic that produces integer literals for the *_I macros

Therefore, we need 365 lines of define the macro.

#define MAP_INC_0 1
#define MAP_INC_1 2
#define MAP_INC_2 3
#define MAP_INC_3 4
#define MAP_INC_4 5
#define MAP_INC_5 6
...

To address this, my approach avoids treating numbers as flat literals. Instead, it represents them as 4-digit tuples (a, b, c, d) and reconstructs the original number as needed. This allows for a much larger range without excessive macro repetition.

I’d appreciate it if you could review the implementation and let me know what changes or refinements would be required to align it with the standards and style of your codebase.

Looking forward to your feedback!

@swansontec
Copy link
Owner

swansontec commented May 29, 2025

Since the MAP_INC stuff has already gotten away from the spirit of the original StackOverflow answer, I suppose the plan going forward is, "if it's useful, and it works, then sure." I do like the simplicity of this math approach.

Does this work on MSVC (the Microsoft C++ compiler)? I'm not sure how to test this easily. If you have a way to test it, then great! Otherwise, maybe I need to find an old Windows laptop for testing.

@Erlkoenig90
Copy link
Contributor

Does this work on MSVC (the Microsoft C++ compiler)? I'm not sure how to test this easily.

Some time ago I already implemented a configuration for GitHub actions for building & testing on GitHub-hosted VMs using GCC, Clang, MSVC. I updated and rebased this onto the current master branch and opened a pull request #14. If you accept that PR and @johnjohnlin then updates their branch the test should automatically run and we can see if it works with MSVC!

@johnjohnlin
Copy link
Author

Thanks for both your reply. I found a MSVC compiler from my friend, and MSVC v143 does not work. Let me figure how to fix...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants