H-Series Application Migration Guide (H06.03+)

Native C and C++ Migration Tasks
H-Series Application Migration Guide429855-006
5-3
Check Programs With Variable-Length Parameter
Lists
Check Programs With Variable-Length Parameter Lists
The TNS/E native C and C++ compilers use 64-bit containers for passing parameters,
instead of the 32-bit containers used by the TNS/R compilers. Programs that directly
manipulate parameter arguments in functions that have a variable-length parameter list
must be changed to manipulate the 64-bit containers. You should use the standard
macros in <stdarg.h> for parameter manipulation. Those macros allow you to write
portable functions that accept a variable number of parameters.
Using setjmp() in Functions Marked as Inline
Calling the setjmp() function in a function marked as inline and then doing a subsequent
longjmp() to the location of the calling function is a practice that should be avoided.
Programs that use setjmp() and longjmp() in this way generally expect that functions
marked as inline are actually inlined, and that the longjmp() call will restore the
execution context of the function that called setjmp().
In TNS/R programs compiled at optimization level 0, this is sometimes the case and
the longmp() call might work as expected. But in a TNS/E program compiled at
optimization level 0, functions marked as inline are never actually inlined, and the
longjmp() call will not restore the context of the function that called setjmp() and give the
expected result. A preferred practice is to use a macro instead of an inline function.
Using the semctl() Function With a Fourth Parameter
The semctl() function has an optional fourth parameter that is required in certain cases.
As described in the Open System Services System Calls Reference Manual, the value
passed in that parameter must be defined in the calling program as a semun union, as
in this example:
union semun {
int val;
struct semid_ds *buf;
unsigned short int *array;
}arg
union semun semopts;
semopts.val = 1;
if (semctl(semid, 0, SETVAL, semopts) ==-1)
On TNS/R systems, you can also pass a value directly, without the use of the semun
union (for example, as a simple scalar), as in this example:
if (semctl(semid, 0, SETVAL, 1) ==1)
A value passed in this way gives the expected results.
However, on TNS/E systems, you must define the parameter value as a semun union.
Code that does not do so will not function as expected.