Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   use of # define in multiple lines and including spaces (http://www.go4expert.com/forums/define-multiple-lines-including-spaces-t12857/)

sandeepmhptr 11Aug2008 14:56

use of # define in multiple lines and including spaces
 
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;\
}

sandeepmhptr 11Aug2008 15:00

Re: use of # define in multiple lines and including spaces
 
sorry for mistake
I wrote that the code also contains comments(not spaces in line no4)

xpi0t0s 11Aug2008 15:51

Re: use of # define in multiple lines and including spaces
 
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?

sandeepmhptr 11Aug2008 15:55

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

sandeepmhptr 11Aug2008 15:57

Re: use of # define in multiple lines and including comments
 
[QUOTE=sandeepmhptr]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 stackk, copy parameters etc...)[/abc]

xpi0t0s 11Aug2008 18:29

Re: use of # define in multiple lines and including spaces
 
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.


All times are GMT +5.5. The time now is 10:12.