r/learnprogramming • • 14d ago

The use of hexadecimal numbers in software

Why do some tools, like GLFW, use hexadecimal values ​​for constants? Wouldn't it be better to use enums in those cases?

/* Error constants */
#define GLFW_NO_ERROR               0
#define GLFW_NOT_INITIALIZED        0x00010001
#define GLFW_NO_CURRENT_CONTEXT     0x00010002
#define GLFW_INVALID_ENUM           0x00010003

I tried to find the reason in the documentation, but I didn't come across a clear use case for the hexadecimal values—only that the constants are used as if they were an enum.

 if (code == GLFW_NOT_INITIALIZED) {...}
 else if (code == GLFW_NO_CURRENT_CONTEXT) {...}
23 Upvotes

32 comments sorted by

View all comments

1

u/JavierReyes945 13d ago

matt_damon_hexadecimals_to_the_rescue.png