简体   繁体   English

一个为Linux编写的C函数没有返回值,C编译器如何处理呢?

[英]no return value from one C function written for linux, how does c compiler deal with that?

I get one program (written for linux originally). 我得到一个程序(最初是为linux编写的)。 I can't understand the syntax of some functions. 我无法理解某些函​​数的语法。 The functions have no return value type. 这些函数没有返回值类型。 Let me give one example 我举一个例子

add_one_point(xx,yy,zz,index)
  float xx,yy,zz;
  int index;
{
 //the implementation 
}

In some functions, the implementations don't return any value, but some really return values. 在某些函数中,实现不返回任何值,但是某些实现确实返回值。 Is this a valid C code? 这是有效的C代码吗? If so, how does c compiler process that? 如果是这样,C编译器如何处理呢?

Thanks in advance! 提前致谢! Jogging 跑步

Older versions of C allowed the return type to be omitted, defaulting it to int . 较旧的C版本允许省略返回类型,将其默认为int

C99 no longer allows it, so if you compiled under C99 mode, it would fail. C99不再允许它,因此,如果在C99模式下编译,它将失败。

You should declare a function not returning any value as returning void , and in any case the return type should be specified. 您应该声明一个不返回任何值的函数为return void ,无论如何都应指定返回类型。 Your compiler might allow you to compiler a function without return value specified (it will default to int, that is why that code might be/have been working), but a modern compiler will at least issue a warning. 您的编译器可能允许您编译未指定返回值的函数(它将默认为int,这就是为什么该代码可能/一直在工作的原因),但是现代的编译器至少会发出警告。

Furthermore, as somebody else already noticed, also the input types are specified in an unusual way (without verifying, I would call it non-standard compliant) 此外,正如其他人已经注意到的那样,输入类型也以不寻常的方式指定(未经验证,我将其称为非标准兼容)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM