1 /*
2 * Copyright (C) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <cstdarg>
16 #include <cstdio>
17
18 #include "testvarargs.h"
19
20 namespace testvarargs {
simpleSumFunction(int a,int b)21 int simpleSumFunction(int a, int b) {
22 printf("Entering simple SUM function\n");
23 return a + b;
24 }
25
26 // count is the number of following arguments
27 // if you want to sum 5 numbers then count should be 5, followed by 5 arguments
varargsSumFunction(int count,...)28 int varargsSumFunction(int count, ...) {
29 printf("Entering variadic arguments SUM function\n");
30 int result = 0;
31
32 std::va_list list;
33 va_start(list, count);
34
35 for (int arg = 0; arg < count; ++arg) {
36 result += va_arg(list, int);
37 }
38
39 va_end(list);
40
41 return result;
42 }
43
44 } // namespace testvarargs