c++ - Can I return early from a variable-argument function? -


suppose have 2 c++ functions debug output:

void trace( const wchar_t* format, ... ) {     va_list args;     va_start( args, format );     varargtrace( format, args );     va_end( args ); }  void varargtrace( const wchar_t* format, va_list args ) {     wchar buffer[1024];     //use ::_vsnwprintf_s format string     ::outputdebugstringw( buffer ); } 

the above uses win32 outputdebugstringw(), doesn't matter. want optimize formatting when there's no debugger attached formatting not done (i measured - speedup significant):

void trace( const wchar_t* format, ... ) {     if( !isdebuggerpresent() ) {         return;     }     //proceed     va_list args;     .....  } 

will fact return once isdebuggerpresent() returns null affect except formatting skipped?

i mean no longer call va_start , va_end - matter? skipping va_start , va_end cause unexpected behavior changes?

the requirement on return if have used (executed) va_start(), must use va_end() before return.

if flout rule, you'll away on systems, system somewhere needs va_end(), don't risk omitting it. undefined behaviour omit it.

other rule, how handle return. proposed return not problem.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -