Based on the comments i ve changed the subject to proc code and i withdraw the claim that it is C++ syntax. Keeping the tags same; as i still hope it is similar to c++ and no ProC tag available please bear with it.
我想这是一个非常新的蜜蜂问题。但由于我没有足够的时间学习 C++ 文档,如果我能获得这方面的帮助,我将不胜感激。
我正在致力于转换类似于 C++ 语法的 pro*C 代码。
这是代码片段
#include <stdio.h>
#include <string.h>
#include <prg_codes.h>
#include <prg_defines.h>
typedef struct
{
int errorflag;
int slot;
} option_info;
int calc_options(currArgc,currArgv,options)
int currArgc;
char *currArgv[];
option_info *options;
{
int optChar;
int invopt=0;
while ((optChar = getopt(currArgc, currArgv, ":s:")) != -1 && !(invopt))
{}
/* other commands */
}
void main(int argc, char *argv[])
{
option_info options;
int rc = 0;
rc=calc_options(argc,argv,&options);
/* other commands */
}
我的问题是
option_info
定义为结构体,然后定义为函数并从 main 调用。还好吗?它是如何工作的?
是option_info
函数内部 calc_options
。因为 option_info 似乎使用了 calc_options 中定义的参数。
或者calc_options
主体被写入包含部分中任何其他文件的其他位置?
最佳答案
此代码段采用古老的 K&R C 语法,该语法早于 ANSI C。然后它会奇怪地缩进,这使得乍一看就像您所描述的那样,但实际上并非如此。 calc_options
是具有三个参数的函数定义,其中第三个参数是指向 typedef option_info 的 options
指针。
这与 ANSI C 语法相同,因此更容易阅读:
int calc_options(int currArgc, char *currArgv[], option_info *options)
{
int optChar;
int invopt=0;
while ((optChar = getopt(currArgc, currArgv, ":s:")) != -1 && !(invopt))
{}
/* other commands */
}
“option_info 被定义为结构”是(以及结构的 typedef)
“然后作为函数并从 main 调用”。 没有
“还好吗?” 是(但应更改为 ANSI 语法)
“它是如何工作的?” 相当不错
“option_info 是否位于函数 calc_options 内?” 这是第三个参数的类型options
“因为 option_info 似乎使用了 calc_options 中定义的参数。” 它是参数选项
的类型
“或者 calc_options 主体被写入包含部分中任何其他文件的其他位置?” 不
关于c++ - pro*C 中没有函数体的函数声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195343/