Thread: Preprocessor help required

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    2

    Preprocessor help required

    Hi
    I am from hardware background and not very good in C programming

    Can any one help me to understand this preprocessor related code PIC C programming
    Code:
    Header file part
    //  No      Rx I/P      Tx O/P      Baud rate 103=9600
    //          ena pin     ena pin     divisor   25=38400
    #define UART_DEFS                           \
    U(1,        C7,         C6,         103)    \
    U(2,        G2,         G1,         25)
    void UartPowerOnInit();
    void UartEnableWakeup();
    bit UartCanSleep();
    void UartsSetWakeTrigger();
    #define U(N,R,T,B)                                                            \
    void Uart##N##TxChar(uint8_t Char);                                         \
    void Uart##N##SetRxCharEvent(enum EVENT_RECIPIENT Recipient,uint8_t Event);
    UART_DEFS
    #undef U
    C File
    Code:
    // Data definitions
    #define U(N,R,T,B)                                           \
                                                                 \
    static TX_PTR      Tx##N##In;                                \
    static TX_PTR      Tx##N##Out;                               \
    static uint8_t     Tx##N##Buff[TX_BUFF_SIZE];                \
                                                                 \
    static enum EVENT_RECIPIENT Rx##N##Recipient;                \
    static uint8_t              Rx##N##Event;                    \
    UART_DEFS
    #undef U
    I am trying to understand use of token, why ## is used before and after identifier

    how and why U is defined twice in same macro


    Over explanation of macro use in this piece of code


    Thanks in advance

    mmuj
    Last edited by Salem; 05-06-2012 at 02:18 PM. Reason: Fixed train-wreck formatting

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Most compilers have a flag to output just the pre-processor step (for gcc, it's the -E flag).

    This shows you what the compiler sees, after all the #includes and #defines have been expanded.

    My guess is you'll see things like
    static TX_PTR Tx1In;
    static TX_PTR Tx1Out;

    static TX_PTR Tx2In;
    static TX_PTR Tx2Out;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    2
    Thanks Salem

    for Hitech Complier it is "--pre" and it gave me answer of my question

    Cheers

    mmuj

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. POI preprocessor ?
    By securelinprog in forum C Programming
    Replies: 2
    Last Post: 02-23-2010, 12:12 AM
  2. preprocessor help
    By brunogon in forum C Programming
    Replies: 13
    Last Post: 06-16-2008, 11:14 AM
  3. preprocessor!!
    By nishu1988 in forum C++ Programming
    Replies: 6
    Last Post: 07-24-2007, 11:31 PM
  4. Preprocessor
    By manutd in forum C++ Programming
    Replies: 5
    Last Post: 11-29-2006, 04:37 PM
  5. C preprocessor
    By Unregisterd in forum C Programming
    Replies: 1
    Last Post: 09-04-2001, 12:17 PM

Tags for this Thread