C 中这个奇怪的函数定义语法是什么? [英] What is this strange function definition syntax in C?

查看:29
本文介绍了C 中这个奇怪的函数定义语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在玩 GNU Bison 时看到了一些这样的函数定义:

I've seen a few function definitions like this recently while playing with GNU Bison:

static VALUE
ripper_pos(self)
    VALUE self;
{
    //code here
}

为什么self的类型在括号之外?这是有效的 C 吗?

Why is the type of self outside of the parenthesis? Is this valid C?

推荐答案

那些是旧的 K&R 风格的函数参数声明,分别声明参数的类型:

Those are old K&R style function parameter declarations, declaring the types of the parameters separately:

int func(a, b, c)
   int a;
   int b;
   int c;
{
  return a + b + c;
}

这与更现代的声明函数参数的方式相同:

This is the same as the more modern way to declare function parameters:

int func(int a, int b, int c)
{
  return a + b + c;
}

新风格"声明基本上是普遍首选的.

The "new style" declarations are basically universally preferred.

这篇关于C 中这个奇怪的函数定义语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆