ILE C/C++ Programmer's Guide


Passing Packed Decimal Data to a Function

There are no default argument promotions on arguments that have packed decimal type when the called function does not include a prototype. This means that any function definition that contains packed decimal arguments has to be prototyped. Otherwise the behavior is undefined. The boundary alignment of an argument with packed decimal type depends on the size of the packed decimal type. To be specific:

The following example shows how to pass packed decimal variables to a function.

Figure 281. ILE C Source to Pass Packed Decimal Variable to a Function




#include <decimal.h>
#include <stdio.h>
decimal(3,1) d1 = 33.3d;
decimal(10,5) d2 = 55555.55555d;
decimal(28) d3 = 8888888888888888888888888888d;
void func1( decimal(3,1), decimal(10,5),
decimal(10,5), decimal(28));


int main(void) {
func1(d1, d2, 999.99d, d3);/* with prototype */
/* The arguments are passed as followed*/
/* 333f0000 00000000 05555555 555f0000 */
/* 99999f00 00000000 00000000 00000000 */
/* 08888888 88888888 88888888 88888f00 */
}
/* func1 is prototyped */
void func1(decimal(3,1) x1, decimal(10,5) x2,
decimal(10,5) x3, decimal(28) x4) {
/* no run-time error when referencing x1, x2, x3 or x4 */
printf("x1 = D(3,1)\n", x1);
printf("x2 = D(10,5)\n", x2);
printf("x3 = D(10,5)\n", x3);
printf("x4 = D(28)\n", x4);
}

The output is as follows:

+--------------------------------------------------------------------------------+
|x1 = 33.3                                                                       |
|x2 = 55555.55555                                                                |
|x3 = 999.99                                                                     |
|x4 = 88888888888888888888888888888                                              |
+--------------------------------------------------------------------------------+


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