Skip to main content
gamedev.net
🔒 Locked

Function guarding

Started by Dirk Gregorius Mar 1, 2004 at 12:46 PM 2 replies 750+ views
Original Post
Dirk Gregorius
Dirk Gregorius
I heard so often about function guarding that I downloaded the Unreal source code to look at it. Can somebode explain what it is used for: 1. What is the reason to put the whole function into additional curly brackets? 2. While the normal guard function stores the name of the function the slow version just add addtional curly brackets? 3. What does the unwind() function do - I didn´''t find the implementation. Maybe somebody can enlight me and explain the concept behind this? Regards, -Dirk
Qw3r7yU10p!
Qw3r7yU10p!
have you looked at the macros?

1) the macro defines a static local variable with a unique name that contains the name of whatever parameter is passed to the macro
2) it''s possible to selectively disable the exception handling so the whole thing is replaced by {}
3) the unwind function will collect the value of the static local variable so it can be retrieved at some other time.
sphinx23
sphinx23
1. For example to avoid double definitions of the variables. so you can do something like:

void MyFunction(void)
{
guard(MyFunction);
guard(InnerGuard);
unguard;
unguard;
}

Without the brackets the compiler would complain about the double definition of __FUNC_NAME__.

2. The guard and guardSlow macros are the same in debug builds. If you build in release mode, guardSlow is replaced by a bracket to not slow down performance.

3. I don''t know if that helps, but my own implementation of this function is as follows:

CORE_API void VARARGS appUnwindf( const TCHAR* Fmt, ... )
{
va_list arglist;
TCHAR Buffer[1024];

static UBOOL Called = 0;

va_start (arglist, Fmt);
if (Called)
appStrcpy( Buffer, TEXT(" <- ") );
else
appStrcpy( Buffer, TEXT("") );
INT Length = _vstprintf( Buffer + appStrlen(Buffer), Fmt, arglist );
Called = 1;
va_end (arglist);

if( appStrlen(GErrorHist)+Length >= 4096 && Length != 0 )
appStrncat( GErrorHist, Buffer, 4096 - appStrlen(GErrorHist) - Length );
else
appStrcat( GErrorHist, Buffer );
}
Dirk Gregorius
Dirk Gregorius
Thanx guys - that helped a lot.

But what information do I get from it? It would make sense to write this information to some log file or so, but the TEXT macro doesn''t do something like this. It is only used for Unicode conversion. I think I need one mor hint

-Dirk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.