ILE C/C++ Programmer's Guide

Passing a Pointer to a Packed Decimal Variable to a Function

The following example shows you how to pass a pointer to a packed decimal variable to a function.

Figure 282. ILE C Source to Pass a Pointer to a Packed Decimal Value to a Function




/* This program shows how to pass a pointer to a packed decimal */
/* variable to a function. */
#include <decimal.h>
#include <stdio.h>
decimal(5,2) var=123.45d;
decimal(5,2) *p=&var;
decimal(5,2) *func_1(decimal(5,2) *);

int main(void)
{
/* Call function with pointer to packed decimal argument. The */
/* value that it returns is also a pointer to a packed decimal. */
if(func_1(p)!=p)
{
printf("Function call not successful\n\n");
}
else
{
printf("The packed decimal number is: %D(5,2)\n",*func_1(p));
}
}
decimal(5,2) *func_1(decimal(5,2) *q)
{
return q;
}

The packed decimal argument in the function call has to be the same type as the packed decimal in the function prototype. If overflow occurs in a function call with packed decimal arguments, no error or warning is issued during compilation, and a run-time exception is generated.

The output is as follows:

+--------------------------------------------------------------------------------+
|  The packed decimal number is: 123.45                                          |
|  Press ENTER to end terminal session.                                          |
+--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents ]