DEFINE in C

Discussion in 'C' started by boschow, May 7, 2007.

  1. boschow

    boschow New Member

    Joined:
    Feb 22, 2007
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    i am not familiar with the #define. I am trying to understand an exaple how to use define, but i dont quite get it, can you guys help me plese. Here is the example:

    /*
    * Define words for adress loockup table (16bit addresses)
    */
    #define GS_CWC1_DRA_WP1 0
    #define GS_CWC1_DRA_WP2 1
    #define GS_CWC1_DRA_WP3 2
    #define GS_CWC1_DRA_WP4 3
    #define GS_CWC1_DRA_WP5 4
    #define GS_CWC2_DRA_WP1 5
    #define GS_CWC2_DRA_WP2 6
    #define GS_CWC2_DRA_WP3 7
    #define GS_CWC2_DRA_WP4 8
    #define GS_CWC2_DRA_WP5 9

    /*
    * Define words for adress loockup table (byte addresses) - The last used base is 31
    */

    #define GS_GS_OF_BS 0
    #define GS_GS_S_BC 1
    #define GS_MA_FC_BS 2
    #define GS_MA_MF_BC 3
    #define GS_RTE_TRC_BC 4
    #define GS_RTE_UHYS_BC 5
    #define GS_RTHF_MA_BC 6
    #define GS_RTPK_MA_BC 7
    #define M11_I1_B_BS 8
    #define M11_I2_B_BS 9

    /*
    * Define bit address and byte address used for Coil MODbus communication definition
    *
    */
    #define aMM_AI1_CV_BS 0 //nvvar->MainModule.AnalogInput1.bb_var.all
    #define aMM_AI1_EA_BC aMM_AI1_CV_BS +1
    #define aMM_AI2_CV_BS aMM_AI1_TA_WP +1
    #define aMM_AI2_EA_BC aMM_AI2_CV_BS +1
    #define aMM_AO1_CS_BC aMM_NTC5_TELA_WP +2
    #define aMM_I1_A_BS aMM_AI2_TB_WP +1
    #define aMM_I2_A_BS aMM_I1_TSW_WP +1
    #define aMM_I3_A_BS aMM_I2_TSW_WP +1

    Thanks for your time and help.
    Best regards,
    BoSCHoW.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    #define is a preprocessor statement. These operations are performed BEFORE the file is submitted to the compiler. In the case of a statement such as
    Code:
    #define THISTHING THATTHING
    
    the token, THISTHING, is replaced in the text, everywhere it occurs, with THATTHING.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You had the thread in the wrong section or I must say not in the Right section. I have moved the thread from programming to C-C++ forum.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice