I’m looking through the source code of a project written in C. Here is a list of options that are defined (no these aren’t the real defines…not very descriptive!)
...
#define OPTION_5 32768
#define OPTION_6 65536
#define OPTION_7 0x20000L
#define OPTION_8 0x40000L
#define OPTION_9 0x80000L
I’d like to add a new option OPTION_10 but before I do that, I’d like to understand what exactly the hex numbers represent?
Do these numbers convert to the expected decimal values of 131,072 262,144 524,288 ? If so, why not keep the same format as the earlier options?
Yes. You can use Google for the conversion: search for “0x20000 in decimal“.
I guess simply because programmers know their powers of two up to 65536 and prefer hexadecimal, where they are more recognizable, above that.
The
Lsuffix forces the literal constant to be typed at least as along int, but the chosen type may be still larger if that’s necessary to hold the constant. It’s probably unnecessary in your program and the programmer used it because s/he didn’t understand the emphasized clause. The nitty-gritty details are in 6.4.4.1, page 56 of the C99 standard.