不带参数的行为C函数

编程入门 行业动态 更新时间:2024-10-17 21:18:45
本文介绍了不带参数的行为C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以解释我为什么以下code编译并没有警告或错误?

我希望编译器警告我说,功能测试不希望任何参数。但是,code编译并运行递归功能测试。

的#include<&stdio.h中GT;#包括LT&;&stdlib.h中GT;静态无效TEST1(INT A,INT B,INT C){}静态无效测试(){    的printf(在这里\\ n);    测试(1,2,3);}无效的主要(){  测试();}

解决方案

在C ++中,无效测试()声明了一个函数,它没有paramerers(并且没有返回)。

在C,无效测试()声明了一个函数,它的参数未指定的(但不是变量)数量(并且没有返回)。因此,所有呼叫都有效(按原型)的温度。

在C,使用无效测试(无效)。

Can somebody explain to me why the following code does compile without a warning or error ?

I would expect the compiler to warn me that the function test doesn't expect any arguments. But the code compiles and runs function test recursively.

#include <stdio.h> #include <stdlib.h> static void test1(int a, int b, int c) {} static void test() { printf("HERE\n"); test(1,2,3); } void main() { test(); }

解决方案

In C++, void test() declares a function that takes no paramerers (and returns nothing).

In C, void test() declares a function that takes an unspecified (but not variable) number of parameters (and returns nothing). So all your calls are valid (according to the prototype) in C.

In C, use void test(void).

更多推荐

不带参数的行为C函数

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

发布评论

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

>www.elefans.com

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