use of # define in multiple lines and including spaces

Discussion in 'C' started by sandeepmhptr, Aug 11, 2008.

  1. sandeepmhptr

    sandeepmhptr New Member

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    My work needs to be done on VC++. I have recently started with this prj.I dont have the licences for Vc++ yet. For shrtage of time I am writing code on notepad. But I can't compile.
    I had a little doubt on my code.

    I have a macro function that spans multiple lines and also has spaces in between.

    I have pasted the code herein........
    Please let me know if this is ths right way to do write this macro.....


    #define gen_badframe_mgmt(ctxt_test_t * ctxt,int a)\//SANDEEP
    //HANDLES BAD FRAME MAGMT FOR BOTH 8K AND 16 K FRAMES
    {\
    /*SANDEEP
    FOR BAD FRAME MGMT*/
    /*ALL CASES ARE--------

    8K FRAME(a=1)
    ---------
    case _AMR_4_75:
    case _AMR_5_9:
    case _AMR_6_7:

    16K FRAME(a=0)
    ---------
    case _AMR_10_2:
    case _AMR_12_65:
    case _AMR_8_85:
    case _AMR_6_6:

    */

    z=0;\
    //int x=0;
    //switch(z=(((ctxt->bad_frame_mgmt)<<6)&&((x=sat_rand(15))!((ctxt->dtx_enable)<<4)!(a<<5)))
    if(ctxt->bad_frame_mgmt)\//TEST IF BAD FRAME MGMT OPTION IS ENABLED IN CTXT VARIABLE
    {//BAD FRAME MGMT ENABLED
    //GENEARATE A RANDOM NUMBER TO BE USED FOR SPEECH_BAD(5), SPEECH_DEGRADED(10), SID_BAD FRAMES(13)
    int x;\
    x=sat_rand(15);\
    switch(z=(x|((ctxt->dtx_enable)<<4)|(a<<5)))\
    {\
    case 5:\
    //0+0+5
    //16K FRAME
    //DTX DISABLED
    //RANDOM NO IS 5
    //ACTIONS---RANDOMLY GENERATE
    //1.SPEECH_BAD FRAMES(5)
    {\
    dst[ctxt->ptr_mod_ctl_bit[21]] = 0;\
    dst[ctxt->ptr_mod_ctl_bit[22]] = 1;\
    }\
    break;\
    case 10:\
    //0+0+10
    //16K FRAME
    //DTX DISABLED
    //RANDOM NO IS 10
    //ACTIONS---RANDOMLY GENERATE
    //2.SPEECH_DEGRADED FRAMES(10)

    {\
    dst[ctxt->ptr_mod_ctl_bit[21]] = 1;\
    dst[ctxt->ptr_mod_ctl_bit[22]] = 0;\

    }\
    break;\

    case 29:\
    //0+16+13
    //16K FRAME
    //DTX ENABLED
    //RANDOM NO IS 13
    //ACTIONS---RANDOMLY GENERATE
    //1.SID_BAD FRAMES(13)

    {\
    dst[ctxt->ptr_mod_data[32]] = 1;\
    dst[ctxt->ptr_mod_data[33]] = 0;\
    dst[ctxt->ptr_mod_data[34]] = 0;\
    }\
    break;\

    case 37:\
    //32+0+5
    //8K FRAME
    //DTX DISABLED
    //RANDOM NO IS 5
    //ACTIONS---RANDOMLY GENERATE
    //1.SPEECH_BAD FRAMES(5)
    {\
    dst[ctxt->ptr_mod_ctl_bit[4]] = 0;\
    dst[ctxt->ptr_mod_ctl_bit[5]] = 1;\
    }\
    break;\

    case 42:\
    //32+0+10
    //8K FRAME
    //DTX DISABLED
    //RANDOM NO IS 10
    //ACTIONS---RANDOMLY GENERATE
    //2.SPEECH_DEGRADED FRAMES(10)

    {\
    dst[ctxt->ptr_mod_ctl_bit[4]] = 1;\
    dst[ctxt->ptr_mod_ctl_bit[5]] = 0;\
    }\
    break;\

    case 61:\
    //32+16+13
    //8K FRAME
    //DTX ENABLED
    //RANDOM NO IS 13
    //ACTIONS---RANDOMLY GENERATE
    //1.SID_BAD FRAMES(13)

    {\
    dst[ctxt->ptr_mod_data[8]] = 1;\
    dst[ctxt->ptr_mod_data[9]] = 0;\
    dst[ctxt->ptr_mod_data[10]]= 0;\
    }\
    break;\
    default:\

    break;\


    }\//END OF SWITCH IN WHICH RANDOM NO IS TESTED
    }\//END OF IF LOOP TO TEST BAD FRAME MGMT


    /*END OF SANDEEP---- BAD FRAME MGMT*/

    return;\
    }
     
  2. sandeepmhptr

    sandeepmhptr New Member

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    sorry for mistake
    I wrote that the code also contains comments(not spaces in line no4)
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Have you profiled your code and found this function to the the major cause of any performance issues?
    If not why do you want this as a macro instead of a function?
     
  4. sandeepmhptr

    sandeepmhptr New Member

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: use of # define in multiple lines and including comments

    the whole of the code needs to run in 20 ms time. so time is an issue. macro best avoids time consumed in function calls(create a task, copy parameters etc...)
     
  5. sandeepmhptr

    sandeepmhptr New Member

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: use of # define in multiple lines and including comments

     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    20ms (0.02s) is quite a long time for a computer, it can do a heck of a lot in that time.
    Does the code already exist as a function, and does the code already fail to meet the target time?

    You haven't answered my question about profiling. How long does the code take to run at present?

    Why do you think creating a stack takes a long time? It's just a case of adding a constant to the stack pointer, and CALL/RETURN statements don't take up much time at all. If you're concerned about parameter passing, pass them in as a pointer to a structure instead although copying a few parameters is just a question of a few microseconds. To be honest the algorithms your code uses are far more likely to be the cause of any performance issues, not the function calling protocol.
     

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