C语言

该页面还没有翻译。

C言语是一个静态型别的程序设计语言

整数型

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(void)
{
  int32_t sum = 0;
  int32_t values[] = {
    1, 2, 3, 4, 5,
  };
  size_t i;

  for (i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
    sum += values[i];
  }
  printf("sum...%" PRId32 "\n", sum);

  return 0;
}

头文件

#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

#include <stdint.h>

enum {
  INT32_SUM_TERMINATE = -1,
};

int32_t int32_sum(int32_t a, ...);

#endif /* FOO_H_INCLUDED */

可変個引数を使う

#include "foo.h"
#include <stdarg.h>

int32_t int32_sum(int32_t a, ...)
{
  int32_t sum = a;
  int32_t arg;
  va_list va;

  va_start(va, a);
  while ((arg = va_arg(va, int32_t)) != INT32_SUM_TERMINATE) {
    sum += arg;
  }
  va_end(va);

  return sum;
}