Why do libraries such as GLFW define related constants with hexadecimal values instead of using an enum? For example:
#define GLFW_NO_ERROR 0
#define GLFW_NOT_INITIALIZED 0x00010001
#define GLFW_NO_CURRENT_CONTEXT 0x00010002
#define GLFW_INVALID_ENUM 0x00010003
These values are compared like enum members, so I'm wondering what advantage the hexadecimal notation provides. Is it mainly for compatibility with C, to make the underlying bit pattern or grouping visible, or is there another practical reason?
3 Answers
Hexadecimal is only a way of writing the integer; the value itself is still just a number. It is useful when the bit pattern matters because each hex digit corresponds to exactly four binary bits. In this example, the shared 0x0001 prefix may identify an error category or leave room for related groups of values, which is much easier to see in hex than in decimal.
Sometimes the numbers are part of an external convention or specification, so changing them could break compatibility. Even when there is no strict external requirement, stable numeric codes are useful when values cross library boundaries, get logged, or are handled by bindings written in other languages. The hexadecimal spelling simply makes those stable values and their structure easier to inspect.
A C enum could technically contain these exact values, but enums in C have limited type-safety and less control over their underlying representation. Named macros or typed integer constants are also easy to expose consistently to other languages and APIs, which matters for a cross-platform library.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically