Scilab<->C 接口中奇怪的函数定义
我正在谈论 Scilab<->C 包装器的示例: http:// /www.scilab.org/doc/intro/node89.html。
奇怪的部分是这个:
int intsfoubare(fname)
char *fname;
{
....(some code)
}
它是某种函数定义,但我真的不明白 char *fname 有什么用处,而且 fname 作为参数对我来说毫无意义。
有人能解释一下吗?
[开始哭泣] 一般来说,Scilabs 文档是一个反面例子,但当涉及到 C 接口时,情况甚至更糟。 [哭完]
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信您看到的是 K&R 风格的函数声明。它大约相当于 int intsfoubare(char *fname) { ... },但在调用函数时允许更灵活。有关更多详细信息,请参阅这篇文章。
I believe what you're looking at is the K&R style of function declaration. It's approximately equivalent to
int intsfoubare(char *fname) { ... }
, but allows more somewhat more flexibility in calling the function. See this post for more details.我不懂 Scilab,但我懂法语!
“foubare”听起来像法语“foobar”。这可能是某些开发人员(不小心?)留下的虚拟或测试函数的情况。
fname
听起来像文件名的名称,作为字符指针传入。也许这会有所帮助。
至于
fname
的使用方式:在较旧的“经典”C 语言定义中,仅将传递参数的名称放在括号中是(事实上仍然是)合法的,并且稍后声明其类型。你不会再看到太多这样的情况了,但这也不是完全错误的。假装括号里写着(char *fname)
。I don't know Scilab, but I know French!
"foubare" sounds like French for "foobar". This could be a case of a dummy or test function some developer (accidentally?) left in place.
fname
sounds like the name of a file name, passed in as a character pointer.Maybe this will help a bit.
As for the way that
fname
is used: In the older, "classic" C language definition, it was (in fact still is) legal to put just the name of a passed parameter in the parentheses, and declare its type later. You don't see much of that any more, but it's not totally wrong either. Just pretend the parentheses say(char *fname)
.这是旧式(1989 年 ANSI/ISO 标准化 C 之前)函数的定义。
如今,有了原型,它就被写成(尽管旧的风格仍然被接受):
That's the old style (before ANSI/ISO standardized C in 1989) definition of functions.
Nowadays with prototypes it is written (though the old style is still accepted) as
根据记录,有关此主题的 Scilab 文档现在好多了!
请参阅:http://help.scilab.org/docs/current/en_US/api_scilab .html
For the record, the Scilab documentation on this subject is now way better!
See: http://help.scilab.org/docs/current/en_US/api_scilab.html