Help us understand the problem. What is going on with this article?

Cの旧関数宣言

More than 3 years have passed since last update.

古いソースコードではANSI C標準以前の関数宣言がある。

旧関数宣言
1 関数定義の引数の型が分離している

void foo(a, b, c)
int a;
int b;
int c;
{
  /* 処理 */
}

2 関数宣言の引数は書かない(書かなくても良い?)

void foo();

何が便利(?)かというとこのような使い方

#define FLOAT_TYPE

/* old declaration */
#if defined (FLOAT_TYPE)
float
#else
int
#endif
add();

/* old definition */
#if defined (FLOAT_TYPE)
float
#else
int
#endif
add(a, b)
#if defined (FLOAT_TYPE)
     float a;
     float b;
#else
     int a;
     int b;
#endif
{
  return a + b;
}

とこのようにすると、一つの関数で型を使い分けできます。

なぜ紹介したかというと、この形式を推奨するのではなく
昔の記述の読み方がわからない人向けに書きました。

私も始めて見た時何が書いてあるか分かりませんでした・・・

参考
C 関数定義 / MSDN
関数の宣言と定義の廃止された形式 / MSDN

uyuni
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした