-
Question about a #define
I saw this code snippet in a recent ACM journal. How does it do what the comment says it does? Is __PMC_CPU a macro defined prior to the snippet shown? How would __PMC_CPUS() be used?
Code:
Figure 2: Translation of constants into descriptive names.
/*
* Kinds of CPUs known
*/
#define __PMC_CPUS() \
__PMC_CPU(AMD_K7, “AMD K7”) \
__PMC_CPU(AMD_K8, “AMD K8”) \
__PMC_CPU(INTEL_P5, “Intel Pentium”) \
__PMC_CPU(INTEL_P6, “Intel Pentium Pro”) \
__PMC_CPU(INTEL_CL, “Intel Celeron”) \
__PMC_CPU(INTEL_PII, “Intel Pentium II”) \
__PMC_CPU(INTEL_PIII, “Intel Pentium III”) \
__PMC_CPU(INTEL_PM, “Intel Pentium M”) \
__PMC_CPU(INTEL_PIV, “Intel Pentium IV”)
-
__PMC_CPU must also be a macro.
A use that I can think of would be to build a lookup table of processor names based on some constant value. For instance, perhaps the #define for AMD_K7 is some hex value that is query-able via a hardware instruction, maybe a value like 0X01EF24 or some other hypothetical value. After getting the chip's hex value, you could run through the table and find its value, and then get the corresponding descriptive string and output that to the user. (Duh, just like the Figure 2. description says)
Todd
-
Thanks, that makes sense.