Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   DEFINE in C (http://www.go4expert.com/forums/define-in-c-t4214/)

boschow 7May2007 19:10

DEFINE in C
 
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.

DaWei 12May2007 18:02

Re: DEFINE in C
 
#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.

shabbir 12May2007 18:12

Re: DEFINE in C
 
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.


All times are GMT +5.5. The time now is 03:39.