U_BIF Macros used in Static or Internal Functions

The U_BIF macros are designed to only reference variables that are passed into them and from the standard Built-In Function parameter list U_BIF_STANDARD_PARAMETERS.

This can create an apparent problem if you try to use the U_BIF macros in a static or internal function within your C program.

For example you might define a static/internal function within your C program like this:

     static void vAverage (X_LONG lArg1, 
                     X_LONG lArg2,
                     1
{
     X_LONG lAverage;
     lAverage = (lArg1 + lArg2) / 2;
     U_BIF_SET_RET_FROM_LONG (sRetNo, lAverage);
     return;
}

To execute this function you might code:

     vAverage (6, 42, 17);

If you do this you will find that it will not compile.

The U_BIF macro being used makes references to pX_Ids, pX_Pro, etc.

These are passed into the "mainline" routine of this function and are in scope there.

However, they are out of scope in this static/internal function and thus will cause compile errors.

You can correct this problem by changing the code to be like this:

     static void vAverage (U_BIF_STANDARD_PARAMETERS,
                        X_LONG lArg1,
                        X_LONG lArg2,
                        X_SHORT sRetNo)
{
   X_LONG lAverage;
   lAverage = (lArg1 + lArg2) / 2;
   U_BIF_SET_RET_FROM_LONG (sRetNo, lAverage);
   return;
}

and then by changing the execution of the function to be like this:

     vAverage (U_BIF_STANDARD_ARGUMENTS, 6, 42, 17);

Of course the behavior of some U_BIF macros is changed when they are used in a static or internal function.

For example, U_BIF_RETURN and U_BIF_ISSUE_FATAL_ERROR return control to the calling function in your program rather than to the calling RDML function.

This means that it is a good idea to test for a fatal error whenever you execute a static or internal function that uses U_BIF macros.

So in this example you could code:

     vAverage (U_BIF_STANDARD_ARGUMENTS, 6, 42, 17);
U_BIF_HANDLE_FATAL_ERROR