是隐含的函数声明合法的C89? [英] Is implicit function declaration legal in C89?

查看:129
本文介绍了是隐含的函数声明合法的C89?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个C程序:

  INT的main()
{
    看跌期权(世界,你好!);
    返回0;
}

这编译和运行良好而据我了解,是合法的C89。不过,我不是100%肯定。在C99模式铿锵编译告诉我,的功能看跌期权隐含的声明是在C99 (这让我觉得C标准必须C99已经改变,使隐性无效函数声明是非法的,这正是我想要确认)。

时隐函数声明合法的C89? (即使这是一个坏主意,做它(除非你在混淆C $ C $Ç挑战))


解决方案

  

时隐函数声明合法的C89?


是的。从部分3.3.2.2


  

如果除权pression是precedes在括号内的参数列表
  函数调用仅由一个标识符,并且如果没有
  声明是可见此标识符,所述标识符是
  隐式声明的完全一样,在最里面块含
  函数调用,声明

 的extern INT标识符();


  
  

出现了。


Consider this C program:

int main()
{
    puts("Hello world!");
    return 0;
}

This compiles and runs fine and as far as I understand, is legal C89. However, I'm not 100% sure about that. Compiling in C99 mode with clang informs me that implicit declaration of function 'puts' is invalid in C99 (which makes me think that the C standard must have changed in C99 to make implicit function declaration illegal, which is what I'm trying to confirm).

Is implicit function declaration legal in C89? (even if it's a bad idea to do it (unless your in an obfuscated C code challenge))

解决方案

Is implicit function declaration legal in C89?

Yes. From section 3.3.2.2:

If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing the function call, the declaration

    extern int  identifier();

appeared.

这篇关于是隐含的函数声明合法的C89?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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