在C:FUNC(空)与FUNC() [英] in c: func(void) vs. func()

查看:211
本文介绍了在C:FUNC(空)与FUNC()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个C函数不接受任何参数,它必须声明/由语言规则是无效的参数定义?
PC-林特似乎有问题的时候,那里已经什么都没有了参数列表,我在想,如果它的东西,在语言的语法,我不知道。

When a C function does not accept any arguments, does it have to be declared/defined with a "void" parameter by the language rules? PC-Lint seems to have problems when there's nothing at all in the argument-list, and I was wondering if it's something in the language syntax that I don't know about.

编辑:我刚刚发现重复(?备份的重复数据删除它首先出现)问题的ç无效参数,该有更多的答案和解释。

I just found a duplicate (back-dupe? it came first) question, C void arguments, which has more answers and explanations.

推荐答案

无效意味着函数不带任何参数。例如,

void means the function does not take any parameters. For example,

int init (void)
{
    return 1;
}

这是不一样的定义

int init ()
{
    return 1;
}

由于在第二种情况下,编译器不会检查功能是否真的叫与所有不带参数; 相反,随着参数的任意数的函数调用将没有任何警告接受(这只是为了与旧式函数定义语法,pre-ANSI兼容性实现)。

because in the second case the compiler will not check whether the function is really called with no arguments at all; instead, a function call with arbitrary number of arguments will be accepted without any warnings (this is implemented only for the compatibility with the old-style function definition syntax, pre-ANSI).

这篇关于在C:FUNC(空)与FUNC()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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