ifx_int8add() 函数将两个 int8 类型值相加。
语法
mint ifx_int8add(n1, n2, sum)
ifx_int8_t *n1;
ifx_int8_t *n2;
ifx_int8_t *sum;
n1
指向包含第一个操作对象的 int8 结构的指针。
n2
指向包含第二个操作对象的 int8 结构的指针。
sum
指向包含 n1 + n2 的和的 int8 结构的指针。
用法
sum 可与 n1 或 n2 相同。
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 714 -
返回代码
0
运算成功。
-1284
运算导致溢出或下溢。
示例
demo 目录中的文件 int8add.ec 包含下列示例程序。
*int8add.ec *
The following program obtains the sum of two INT8 type values.
*/
#include
EXEC SQL include "int8.h";
char string1[] = "6";
char string2[] = "9,223,372,036,854,775";
char string3[] = "999,999,999,999,999,9995";
char result[41];
main()
{
mint x;
ifx_int8_t num1, num2, num3, sum;
printf("INT8 Sample ESQL Program running.\n\n");
if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 715 -
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num1, &num2, ∑)) /* adding the first two INT8s */
{
printf("Error %d in adding INT8s\n", x);
exit(1);
}
if (x = ifx_int8soasc(∑, result, sizeof(result)))
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string1, string2, result); /* display result */
/* attempt to convert to INT8 value that is too large*/
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num2, &num3, ∑))
{
printf("Error %d in adding INT8s\n", x);
exit (1);
}
if (x = ifx_int8soasc(∑, result, sizeof(result)))
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 716 -
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string2, string3, result); /* display result */
printf("\nINT8 Sample Program over.\n\n");
exit(0);
}
输出
INT8 Sample ESQL Program running.
6 + 9,223,372,036,854,775 = 9223372036854781
Error -1284 in converting string3 to INT8
INT8 Sample Program over.