Thread: Question about a #define

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    54

    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”)

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    __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
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    54
    Thanks, that makes sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing syscalls from C
    By lilcoder in forum C Programming
    Replies: 17
    Last Post: 09-19-2007, 02:27 PM
  2. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  3. macro (#define) question
    By Darrok in forum C++ Programming
    Replies: 30
    Last Post: 12-20-2001, 05:01 PM
  4. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM