c - using #define #ifdef for conditions -
GCC 4.7.2 c89 Hello, < P> I have the following code that I think the RTP stream will not be modified
#define DO_MODIFY_RTP #ifdef DO_NOT_MODIFY_RTP if (modify_rtp_media_stream (channel> IPM) = = FALSE). {Status = false; } #endif When I want to modify the RTP stream, I will set it to #define : #define DO_MODIFY_RTP #ifdef DO_MODIFY_RTP if (modify_rtp_media_stream (channel-> ipm) == incorrect) {status = FALSE; } #endif Eventually it will be controlled by a property in a configuration file.
Is it strange to use #define in this way? Many thanks for any suggestions,
Generally, Do not want to modify the code, so you'll probably do something like this:
#undef MODIFY_RTP #if define (DO_NOT_MODIFY_RTP) #define MODIFY_RTP 0 #else #define MODIFY_RTP 1 #endif if ( MODIFY_RTP) {if (modify_rtp_media_stream (channel> IPM) == incorrect) position = FALSE; } You may type -DDO_NOT_MODIFY_RTP on the compiler command line, or in a configuration header, you can type #define DO_NOT_MODIFY_RTP And the RTP section will not be changed. By excluding the definition of DO_NOT_MODIFY_RTP the macro, the function will be called and the RTP section can be modified. Or you can reverse the condition so that the default is not to modify the stream:
#if define (DO_MODIFY_RTP) #define MODIFY_RTP 1 #else #define MODIFY_RTP 0 #endif The big advantage of the code shown is that it is always compiled ??? But will end the call to adapter modify_rtp_media_stream () if MODIFY_RTP is 0. This means that the compiler checks the syntax of the statement, so it is not out of date as the code This change around. The debug code gets decayed, if it is not compiled as a code, changes around it, but the compiler does not inform you about problems because the preprocessor has removed the code so that the compiler is not shown as appropriate. Gives
Comments
Post a Comment