使用"无效"用C

编程入门 行业动态 更新时间:2024-10-24 17:26:25
本文介绍了使用"无效"用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很困惑,为什么我们需要传递无效进入C函数:

I'm confused about why we need to pass void into C functions:

int f(void) { return 0; }

int f() { return 0; }

什么是正确的事情,为什么?

What is the proper thing to do and why?

推荐答案

在C, INT F()是一个旧式的声明。它说,˚F需要一个固定的,但数目不详和参数类型(S)。例如,给定 INT F(){返回0; } ,编译器不会抱怨 F(42)或 F(你好,世界)(尽管这种调用的行为是不确定的)。

In C, int f() is an old-style declaration. It says that f expects a fixed but unspecified number and type(s) of arguments. For example, given int f() { return 0; }, the compiler won't complain about f(42), or f("hello, world") (though the behavior of such a call is undefined).

INT F(无效)明确地说,˚F不带任何参数。

int f(void) explicitly says that f takes no arguments.

(C ++有不同的规则。斯特劳斯并不像关心与旧的C code向后兼容)

(C++ has different rules; Stroustrup wasn't as concerned about backward compatibility with old C code.)

更多推荐

使用"无效"用C

本文发布于:2023-05-25 10:54:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!