strange function definition in Scilab<->C interface

…衆ロ難τιáo~ 提交于 2019-12-20 05:46:11

问题


I'am talking about this example of a Scilab<->C wrapper: http://www.scilab.org/doc/intro/node89.html.

The strange part is this one:

int intsfoubare(fname) 
 char *fname;
   {
     ....(some code)
   }

It is some kind of function defintion but I really don't understand what the char *fname is good for also just fname as parameter makes no sense to me.

Is someone able to explain this?

[start crying] Scilabs documentation in general is a negative example but when it comes to the C-interface it's even worse. [end crying]

Thanks!


回答1:


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.




回答2:


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) .




回答3:


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

int intsfoubare(char *fname)
{
    ....(some code)
}



回答4:


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



来源:https://stackoverflow.com/questions/1808355/strange-function-definition-in-scilab-c-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!