Isn't it better to generate a mask by a preprocessor macro when the shift value and data length are #define like OP?
reply #14, but not 'const'
Preprocessor macros are not type safe, and can cause quirky syntax errors if not carefully written. That is why I prefer using 'const' variables instead as in reply #14.
Yeah, maybe the reason I think so...
I often work under strict processing speed and memory conditions, and I'm in a world where hard coded magic number is heavily used... ![]()
Unless there is such a reason in OP, there is no problem to use constants. ![]()
Constants do not create any overhead in the compiled code. They are optimized away.
I'm trying hard to imagine a world that needs hard coded magic numbers. Even most of the assembly language code I've seen and produced, used mostly identifiers, not magic numbers. In C, consider the Arduino core. All the register definitions and many more important values have identifiers.
Ah sorry, I didn't mean I didn't give it an identification name. It always exists.
Certainly it may not be commonly called a magic number.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.